pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix parsing of integer values for connection parameters in libpq
5+ messages / 2 participants
[nested] [flat]

Commits from this thread:
  2019-10-23 57379cd5ac a6a95d4f38  Fix thinkos from 4f4061b for libpq integer parsing
* pgsql: Fix parsing of integer values for connection parameters in libpq
@ 2019-10-21 02:18 Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 5+ messages in thread

From: Michael Paquier @ 2019-10-21 02:18 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix parsing of integer values for connection parameters in libpq

Commit e7a2217 has introduced stricter checks for integer values in
connection parameters for libpq.  However this failed to correctly check
after trailing whitespaces, while leading whitespaces were discarded per
the use of strtol(3).  This fixes and refactors the parsing logic to
handle both cases consistently.  Note that trying to restrict the use of
trailing whitespaces can easily break connection strings like in ECPG
regression tests (these have allowed me to catch the parsing bug with
connect_timeout).

Author: Michael Paquier
Reviewed-by: Lars Kanis
Discussion: https://postgr.es/m/a9b4cbd7-4ecb-06b2-ebd7-1739bbff3217@greiz-reinsdorf.de
Backpatch-through: 12

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/4f4061b2dde178d2ab79d1ee3b1ae3c62c117926

Modified Files
--------------
src/interfaces/libpq/fe-connect.c | 29 +++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Fix parsing of integer values for connection parameters in libpq
@ 2019-10-21 02:18 Michael Paquier <michael@paquier.xyz>
  2019-10-22 08:05 ` Re: pgsql: Fix parsing of integer values for connection parameters in libpq Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Michael Paquier @ 2019-10-21 02:18 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix parsing of integer values for connection parameters in libpq

Commit e7a2217 has introduced stricter checks for integer values in
connection parameters for libpq.  However this failed to correctly check
after trailing whitespaces, while leading whitespaces were discarded per
the use of strtol(3).  This fixes and refactors the parsing logic to
handle both cases consistently.  Note that trying to restrict the use of
trailing whitespaces can easily break connection strings like in ECPG
regression tests (these have allowed me to catch the parsing bug with
connect_timeout).

Author: Michael Paquier
Reviewed-by: Lars Kanis
Discussion: https://postgr.es/m/a9b4cbd7-4ecb-06b2-ebd7-1739bbff3217@greiz-reinsdorf.de
Backpatch-through: 12

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/2b0f959b5119cb2bb1d135ac04a8c5272bbcab03

Modified Files
--------------
src/interfaces/libpq/fe-connect.c | 29 +++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: pgsql: Fix parsing of integer values for connection parameters in libpq
  2019-10-21 02:18 pgsql: Fix parsing of integer values for connection parameters in libpq Michael Paquier <michael@paquier.xyz>
@ 2019-10-22 08:05 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2019-10-22 10:05   ` Re: pgsql: Fix parsing of integer values for connection parameters in libpq Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 5+ messages in thread

From: Peter Eisentraut @ 2019-10-22 08:05 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; pgsql-committers@lists.postgresql.org

On 2019-10-21 04:18, Michael Paquier wrote:
> Fix parsing of integer values for connection parameters in libpq

Something in this code doesn't make sense:

+   /*
+    * Skip any trailing whitespace; if anything but whitespace remains
before
+    * the terminating character, fail
+    */
+   while (*end && *end != '\0' && isspace((unsigned char) *end))
+       end++;
+
+   if (*end && *end != '\0')
+       goto error;

You probably want something like

    if (end && *end != ...)

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: pgsql: Fix parsing of integer values for connection parameters in libpq
  2019-10-21 02:18 pgsql: Fix parsing of integer values for connection parameters in libpq Michael Paquier <michael@paquier.xyz>
  2019-10-22 08:05 ` Re: pgsql: Fix parsing of integer values for connection parameters in libpq Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
@ 2019-10-22 10:05   ` Michael Paquier <michael@paquier.xyz>
  2019-10-23 02:37     ` Re: pgsql: Fix parsing of integer values for connection parameters in libpq Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 5+ messages in thread

From: Michael Paquier @ 2019-10-22 10:05 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: pgsql-committers@lists.postgresql.org

On Tue, Oct 22, 2019 at 10:05:45AM +0200, Peter Eisentraut wrote:
> You probably want something like
> 
>     if (end && *end != ...)

Yes, it looks like a brain fade here.  Conversion failures are tracked
before that, so strtol() would not return NULL for endptr.  The first
part could just be removed as per the attached. 
--
Michael

Attachments:

libpq-parse-fix.patch (text/x-diff, 621B) download diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 9af830321c..0eeabb8b43 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -1713,10 +1713,10 @@ parse_int_param(const char *value, int *result, PGconn *conn, * Skip any trailing whitespace; if anything but whitespace remains before * the terminating character, fail */ - while (*end && *end != '\0' && isspace((unsigned char) *end)) + while (*end != '\0' && isspace((unsigned char) *end)) end++; - if (*end && *end != '\0') + if (*end != '\0') goto error; *result = numval;
signature.asc (application/pgp-signature, 832B) download ^ permalink raw reply [nested|flat] 5+ messages in thread

* Re: pgsql: Fix parsing of integer values for connection parameters in libpq
  2019-10-21 02:18 pgsql: Fix parsing of integer values for connection parameters in libpq Michael Paquier <michael@paquier.xyz>
  2019-10-22 08:05 ` Re: pgsql: Fix parsing of integer values for connection parameters in libpq Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2019-10-22 10:05   ` Re: pgsql: Fix parsing of integer values for connection parameters in libpq Michael Paquier <michael@paquier.xyz>
@ 2019-10-23 02:37     ` Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 5+ messages in thread

From: Michael Paquier @ 2019-10-23 02:37 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: pgsql-committers@lists.postgresql.org

On Tue, Oct 22, 2019 at 07:05:53PM +0900, Michael Paquier wrote:
> Yes, it looks like a brain fade here.  Conversion failures are tracked
> before that, so strtol() would not return NULL for endptr.  The first
> part could just be removed as per the attached. 

I looked at that with a fresher mind, and fixed it, with an extra
assertion making sure that we never call it with a NULL input.  All
callers of parse_int_param are careful to not call the routine with a
NULL input, but future callers may not be that careful...
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2019-10-23 02:37 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-10-21 02:18 pgsql: Fix parsing of integer values for connection parameters in libpq Michael Paquier <michael@paquier.xyz>
2019-10-21 02:18 pgsql: Fix parsing of integer values for connection parameters in libpq Michael Paquier <michael@paquier.xyz>
2019-10-22 08:05 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2019-10-22 10:05   ` Michael Paquier <michael@paquier.xyz>
2019-10-23 02:37     ` Michael Paquier <michael@paquier.xyz>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox