Skip to content

Commit c7a2010

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 97dccef commit c7a2010

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
@@ -2168,14 +2168,14 @@ connectFailureMessage(PGconn *conn, int errorno)
21682168
static int
21692169
useKeepalives(PGconn *conn)
21702170
{
2171-
char *ep;
21722171
int val;
21732172

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

@@ -3083,7 +3083,7 @@ PQconnectPoll(PGconn *conn)
30833083

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

0 commit comments

Comments
 (0)