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