Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2b0f959

Browse files
committed
Fix parsing of integer values for connection parameters in libpq
Commite7a2217 has introduced stricter checks for integer values inconnection parameters for libpq. However this failed to correctly checkafter trailing whitespaces, while leading whitespaces were discarded perthe use of strtol(3). This fixes and refactors the parsing logic tohandle both cases consistently. Note that trying to restrict the use oftrailing whitespaces can easily break connection strings like in ECPGregression tests (these have allowed me to catch the parsing bug withconnect_timeout).Author: Michael PaquierReviewed-by: Lars KanisDiscussion:https://postgr.es/m/a9b4cbd7-4ecb-06b2-ebd7-1739bbff3217@greiz-reinsdorf.deBackpatch-through: 12
1 parentef13f91 commit2b0f959

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

‎src/interfaces/libpq/fe-connect.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,7 +1654,7 @@ useKeepalives(PGconn *conn)
16541654
/*
16551655
* Parse and try to interpret "value" as an integer value, and if successful,
16561656
* store it in *result, complaining if there is any trailing garbage or an
1657-
* overflow.
1657+
* overflow. This allows any number of leading and trailing whitespaces.
16581658
*/
16591659
staticbool
16601660
parse_int_param(constchar*value,int*result,PGconn*conn,
@@ -1665,14 +1665,31 @@ parse_int_param(const char *value, int *result, PGconn *conn,
16651665

16661666
*result=0;
16671667

1668+
/* strtol(3) skips leading whitespaces */
16681669
errno=0;
16691670
numval=strtol(value,&end,10);
1670-
if (errno==0&&*end=='\0'&&numval== (int)numval)
1671-
{
1672-
*result=numval;
1673-
return true;
1674-
}
16751671

1672+
/*
1673+
* If no progress was done during the parsing or an error happened, fail.
1674+
* This tests properly for overflows of the result.
1675+
*/
1676+
if (value==end||errno!=0||numval!= (int)numval)
1677+
gotoerror;
1678+
1679+
/*
1680+
* Skip any trailing whitespace; if anything but whitespace remains before
1681+
* the terminating character, fail
1682+
*/
1683+
while (*end&&*end!='\0'&&isspace((unsignedchar)*end))
1684+
end++;
1685+
1686+
if (*end&&*end!='\0')
1687+
gotoerror;
1688+
1689+
*result=numval;
1690+
return true;
1691+
1692+
error:
16761693
appendPQExpBuffer(&conn->errorMessage,
16771694
libpq_gettext("invalid integer value \"%s\" for connection option \"%s\"\n"),
16781695
value,context);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp