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

Commit4f4061b

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 parentea9e06a commit4f4061b

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
@@ -1687,7 +1687,7 @@ useKeepalives(PGconn *conn)
16871687
/*
16881688
* Parse and try to interpret "value" as an integer value, and if successful,
16891689
* store it in *result, complaining if there is any trailing garbage or an
1690-
* overflow.
1690+
* overflow. This allows any number of leading and trailing whitespaces.
16911691
*/
16921692
staticbool
16931693
parse_int_param(constchar*value,int*result,PGconn*conn,
@@ -1698,14 +1698,31 @@ parse_int_param(const char *value, int *result, PGconn *conn,
16981698

16991699
*result=0;
17001700

1701+
/* strtol(3) skips leading whitespaces */
17011702
errno=0;
17021703
numval=strtol(value,&end,10);
1703-
if (errno==0&&*end=='\0'&&numval== (int)numval)
1704-
{
1705-
*result=numval;
1706-
return true;
1707-
}
17081704

1705+
/*
1706+
* If no progress was done during the parsing or an error happened, fail.
1707+
* This tests properly for overflows of the result.
1708+
*/
1709+
if (value==end||errno!=0||numval!= (int)numval)
1710+
gotoerror;
1711+
1712+
/*
1713+
* Skip any trailing whitespace; if anything but whitespace remains before
1714+
* the terminating character, fail
1715+
*/
1716+
while (*end&&*end!='\0'&&isspace((unsignedchar)*end))
1717+
end++;
1718+
1719+
if (*end&&*end!='\0')
1720+
gotoerror;
1721+
1722+
*result=numval;
1723+
return true;
1724+
1725+
error:
17091726
appendPQExpBuffer(&conn->errorMessage,
17101727
libpq_gettext("invalid integer value \"%s\" for connection option \"%s\"\n"),
17111728
value,context);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp