@@ -293,8 +293,6 @@ pqParseInput3(PGconn *conn)
293
293
/* First 'T' in a query sequence */
294
294
if (getRowDescriptions (conn , msgLength ))
295
295
return ;
296
- /* getRowDescriptions() moves inStart itself */
297
- continue ;
298
296
}
299
297
else
300
298
{
@@ -340,17 +338,14 @@ pqParseInput3(PGconn *conn)
340
338
case 't' : /* Parameter Description */
341
339
if (getParamDescriptions (conn , msgLength ))
342
340
return ;
343
- /* getParamDescriptions() moves inStart itself */
344
- continue ;
341
+ break ;
345
342
case 'D' : /* Data Row */
346
343
if (conn -> result != NULL &&
347
344
conn -> result -> resultStatus == PGRES_TUPLES_OK )
348
345
{
349
346
/* Read another tuple of a normal query response */
350
347
if (getAnotherTuple (conn , msgLength ))
351
348
return ;
352
- /* getAnotherTuple() moves inStart itself */
353
- continue ;
354
349
}
355
350
else if (conn -> result != NULL &&
356
351
conn -> result -> resultStatus == PGRES_FATAL_ERROR )
@@ -467,7 +462,6 @@ handleSyncLoss(PGconn *conn, char id, int msgLength)
467
462
* command for a prepared statement) containing the attribute data.
468
463
* Returns: 0 if processed message successfully, EOF to suspend parsing
469
464
* (the latter case is not actually used currently).
470
- * In the former case, conn->inStart has been advanced past the message.
471
465
*/
472
466
static int
473
467
getRowDescriptions (PGconn * conn , int msgLength )
@@ -572,19 +566,9 @@ getRowDescriptions(PGconn *conn, int msgLength)
572
566
result -> binary = 0 ;
573
567
}
574
568
575
- /* Sanity check that we absorbed all the data */
576
- if (conn -> inCursor != conn -> inStart + 5 + msgLength )
577
- {
578
- errmsg = libpq_gettext ("extraneous data in \"T\" message" );
579
- goto advance_and_error ;
580
- }
581
-
582
569
/* Success! */
583
570
conn -> result = result ;
584
571
585
- /* Advance inStart to show that the "T" message has been processed. */
586
- conn -> inStart = conn -> inCursor ;
587
-
588
572
/*
589
573
* If we're doing a Describe, we're done, and ready to pass the result
590
574
* back to the client.
@@ -608,9 +592,6 @@ getRowDescriptions(PGconn *conn, int msgLength)
608
592
if (result && result != conn -> result )
609
593
PQclear (result );
610
594
611
- /* Discard the failed message by pretending we read it */
612
- conn -> inStart += 5 + msgLength ;
613
-
614
595
/*
615
596
* Replace partially constructed result with an error result. First
616
597
* discard the old result to try to win back some memory.
@@ -629,6 +610,12 @@ getRowDescriptions(PGconn *conn, int msgLength)
629
610
printfPQExpBuffer (& conn -> errorMessage , "%s\n" , errmsg );
630
611
pqSaveErrorResult (conn );
631
612
613
+ /*
614
+ * Show the message as fully consumed, else pqParseInput3 will overwrite
615
+ * our error with a complaint about that.
616
+ */
617
+ conn -> inCursor = conn -> inStart + 5 + msgLength ;
618
+
632
619
/*
633
620
* Return zero to allow input parsing to continue. Subsequent "D"
634
621
* messages will be ignored until we get to end of data, since an error
@@ -640,12 +627,8 @@ getRowDescriptions(PGconn *conn, int msgLength)
640
627
/*
641
628
* parseInput subroutine to read a 't' (ParameterDescription) message.
642
629
* We'll build a new PGresult structure containing the parameter data.
643
- * Returns: 0 if completed message, EOF if not enough data yet.
644
- * In the former case, conn->inStart has been advanced past the message.
645
- *
646
- * Note that if we run out of data, we have to release the partially
647
- * constructed PGresult, and rebuild it again next time. Fortunately,
648
- * that shouldn't happen often, since 't' messages usually fit in a packet.
630
+ * Returns: 0 if processed message successfully, EOF to suspend parsing
631
+ * (the latter case is not actually used currently).
649
632
*/
650
633
static int
651
634
getParamDescriptions (PGconn * conn , int msgLength )
@@ -685,33 +668,19 @@ getParamDescriptions(PGconn *conn, int msgLength)
685
668
result -> paramDescs [i ].typid = typid ;
686
669
}
687
670
688
- /* Sanity check that we absorbed all the data */
689
- if (conn -> inCursor != conn -> inStart + 5 + msgLength )
690
- {
691
- errmsg = libpq_gettext ("extraneous data in \"t\" message" );
692
- goto advance_and_error ;
693
- }
694
-
695
671
/* Success! */
696
672
conn -> result = result ;
697
673
698
- /* Advance inStart to show that the "t" message has been processed. */
699
- conn -> inStart = conn -> inCursor ;
700
-
701
674
return 0 ;
702
675
703
676
not_enough_data :
704
- PQclear (result );
705
- return EOF ;
677
+ errmsg = libpq_gettext ("insufficient data in \"t\" message" );
706
678
707
679
advance_and_error :
708
680
/* Discard unsaved result, if any */
709
681
if (result && result != conn -> result )
710
682
PQclear (result );
711
683
712
- /* Discard the failed message by pretending we read it */
713
- conn -> inStart += 5 + msgLength ;
714
-
715
684
/*
716
685
* Replace partially constructed result with an error result. First
717
686
* discard the old result to try to win back some memory.
@@ -729,6 +698,12 @@ getParamDescriptions(PGconn *conn, int msgLength)
729
698
printfPQExpBuffer (& conn -> errorMessage , "%s\n" , errmsg );
730
699
pqSaveErrorResult (conn );
731
700
701
+ /*
702
+ * Show the message as fully consumed, else pqParseInput3 will overwrite
703
+ * our error with a complaint about that.
704
+ */
705
+ conn -> inCursor = conn -> inStart + 5 + msgLength ;
706
+
732
707
/*
733
708
* Return zero to allow input parsing to continue. Essentially, we've
734
709
* replaced the COMMAND_OK result with an error result, but since this
@@ -742,7 +717,6 @@ getParamDescriptions(PGconn *conn, int msgLength)
742
717
* We fill rowbuf with column pointers and then call the row processor.
743
718
* Returns: 0 if processed message successfully, EOF to suspend parsing
744
719
* (the latter case is not actually used currently).
745
- * In the former case, conn->inStart has been advanced past the message.
746
720
*/
747
721
static int
748
722
getAnotherTuple (PGconn * conn , int msgLength )
@@ -815,28 +789,14 @@ getAnotherTuple(PGconn *conn, int msgLength)
815
789
}
816
790
}
817
791
818
- /* Sanity check that we absorbed all the data */
819
- if (conn -> inCursor != conn -> inStart + 5 + msgLength )
820
- {
821
- errmsg = libpq_gettext ("extraneous data in \"D\" message" );
822
- goto advance_and_error ;
823
- }
824
-
825
- /* Advance inStart to show that the "D" message has been processed. */
826
- conn -> inStart = conn -> inCursor ;
827
-
828
792
/* Process the collected row */
829
793
errmsg = NULL ;
830
794
if (pqRowProcessor (conn , & errmsg ))
831
795
return 0 ; /* normal, successful exit */
832
796
833
- goto set_error_result ; /* pqRowProcessor failed, report it */
797
+ /* pqRowProcessor failed, fall through to report it */
834
798
835
799
advance_and_error :
836
- /* Discard the failed message by pretending we read it */
837
- conn -> inStart += 5 + msgLength ;
838
-
839
- set_error_result :
840
800
841
801
/*
842
802
* Replace partially constructed result with an error result. First
@@ -856,6 +816,12 @@ getAnotherTuple(PGconn *conn, int msgLength)
856
816
printfPQExpBuffer (& conn -> errorMessage , "%s\n" , errmsg );
857
817
pqSaveErrorResult (conn );
858
818
819
+ /*
820
+ * Show the message as fully consumed, else pqParseInput3 will overwrite
821
+ * our error with a complaint about that.
822
+ */
823
+ conn -> inCursor = conn -> inStart + 5 + msgLength ;
824
+
859
825
/*
860
826
* Return zero to allow input parsing to continue. Subsequent "D"
861
827
* messages will be ignored until we get to end of data, since an error
0 commit comments