Skip to content

Commit 920d519

Browse files
committed
Parse libpq's "keepalives" option more like other integer options.
Use pqParseIntParam (nee parse_int_param) instead of using strtol directly. This allows trailing whitespace, which the previous coding didn't, and makes the spelling of the error message consistent with other similar cases. This seems to be an oversight in commit e7a2217, which introduced parse_int_param. That fixed places that were using atoi(), but missed this place which was randomly using strtol() instead. Ordinarily I'd consider this minor cleanup not worth back-patching. However, it seems that ecpg assumes it can add trailing whitespace to URL parameters, so that use of the keepalives option fails in that context. Perhaps that's worth improving as a separate matter. In the meantime, back-patch this to all supported branches. Yuto Sasaki (some further cleanup by me) Discussion: https://postgr.es/m/TY2PR01MB36286A7B97B9A15793335D18C1772@TY2PR01MB3628.jpnprd01.prod.outlook.com
1 parent d94cf5c commit 920d519

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/interfaces/libpq/fe-connect.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,14 +2169,14 @@ connectFailureMessage(PGconn *conn, int errorno)
21692169
static int
21702170
useKeepalives(PGconn *conn)
21712171
{
2172-
char *ep;
21732172
int val;
21742173

21752174
if (conn->keepalives == NULL)
21762175
return 1;
2177-
val = strtol(conn->keepalives, &ep, 10);
2178-
if (*ep)
2176+
2177+
if (!pqParseIntParam(conn->keepalives, &val, conn, "keepalives"))
21792178
return -1;
2179+
21802180
return val != 0 ? 1 : 0;
21812181
}
21822182

@@ -3084,7 +3084,7 @@ PQconnectPoll(PGconn *conn)
30843084

30853085
if (usekeepalives < 0)
30863086
{
3087-
libpq_append_conn_error(conn, "keepalives parameter must be an integer");
3087+
/* error is already reported */
30883088
err = 1;
30893089
}
30903090
else if (usekeepalives == 0)

0 commit comments

Comments
 (0)