[BUG FIX]Connection fails with whitespace after keepalives parameter value
Yuto Sasaki (Fujitsu) <sasaki.yuto-00@fujitsu.com>
From: "Yuto Sasaki (Fujitsu)" <sasaki.yuto-00@fujitsu.com>
To: "pgsql-hackers@lists.postgresql.org" <pgsql-hackers@lists.postgresql.org>
Date: 2024-10-01T05:11:21Z
Lists: pgsql-hackers
Attachments
- test.pgc (application/octet-stream)
- keepalives.diffs (application/octet-stream)
Hi hackers, I've discovered a bug in ECPG that causes database connection failures. This issue appears to stem from libpq layer. Found bug: The EXEC SQL CONNECT TO statement fails to connect to the database. Specifically, the following code: ```c EXEC SQL CONNECT TO tcp:postgresql://localhost:5432/postgres?keepalives=1 &keepalives_idle=1 USER yuto; ``` When precompiled and executed, this code fails to connect to the database. Error message: ``` failed: keepalives parameter must be an integer ``` Steps to reproduce: The issue can be reproduced using the attached pgc file. Root cause: The method for parsing the keepalives parameter in the useKeepalives function of the libpq library is not appropriate. Specifically, it doesn't account for whitespace following the numeric value. Proposed fix: strtol() can be replaced with pqParseIntParam() like other paramters. This skips whitespaces. Concerns: 1. This fix may limit parameter values to integers only. Example: keepalives=2147483648 (values larger than INT_MAX can't be read) 2. Whitespace after '=' that was previously not read will now be read. Example: keepalives= 1 (previously couldn't be read, now read as 1) 3. This issue was introduced in previous versions (as far as I could verify, from 9.0), so we may need to consider backpatching if necessary. These concerns warrant further discussion. I'd appreciate your review of this patch and these concerns. Thank you.
Commits
-
libpq: Discard leading and trailing spaces for parameters and values in URIs
- 430ce189fc45 18.0 landed
-
ecpg: avoid adding whitespace around '&' in connection URLs.
- f22e84df1dea 18.0 landed
-
Parse libpq's "keepalives" option more like other integer options.
- e7af9b52f679 14.14 landed
- c7a201053e3f 17.1 landed
- bb8c89dbcde7 15.9 landed
- 920d51979a99 18.0 landed
- 65f431affda8 16.5 landed
- 47d8a15deaeb 12.21 landed
- 2120eda94420 13.17 landed