pgsql: Re-simplify management of inStart in pqParseInput3's subroutines

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Re-simplify management of inStart in pqParseInput3's subroutines
Date: 2021-03-11 19:44:07
Message-ID: E1lKRE7-0004t7-1Q@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Re-simplify management of inStart in pqParseInput3's subroutines.

Commit 92785dac2 copied some logic related to advancement of inStart
from pqParseInput3 into getRowDescriptions and getAnotherTuple,
because it wanted to allow user-defined row processor callbacks to
potentially longjmp out of the library, and inStart would have to be
updated before that happened to avoid an infinite loop. We later
decided that that API was impossibly fragile and reverted it, but
we didn't undo all of the related code changes, and this bit of
messiness survived. Undo it now so that there's just one place in
pqParseInput3's processing where inStart is advanced; this will
simplify addition of better tracing support.

getParamDescriptions had grown similar processing somewhere along
the way (not in 92785dac2; I didn't track down just when), but it's
actually buggy because its handling of corrupt-message cases seems to
have been copied from the v2 logic where we lacked a known message
length. The cases where we "goto not_enough_data" should not simply
return EOF, because then we won't consume the message, potentially
creating an infinite loop. That situation now represents a
definitively corrupt message, and we should report it as such.

Although no field reports of getParamDescriptions getting stuck in
a loop have been seen, it seems appropriate to back-patch that fix.
I chose to back-patch all of this to keep the logic looking more alike
in supported branches.

Discussion: https://postgr.es/m/2217283.1615411989@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/51c54bb603098416dc6f9d9d46a3d14861f8fc38

Modified Files
--------------
src/interfaces/libpq/fe-protocol3.c | 80 +++++++++++--------------------------
1 file changed, 23 insertions(+), 57 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Robert Haas 2021-03-11 20:33:34 pgsql: Be clear about whether a recovery pause has taken effect.
Previous Message Peter Geoghegan 2021-03-11 19:42:58 Re: pgsql: Don't consider newly inserted tuples in nbtree VACUUM.