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

Commit399a570

Browse files
committed
int8in failed to detect overflow; it really should.
1 parentf40c506 commit399a570

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

‎src/backend/utils/adt/int8.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ int8in(char *str)
5959

6060
/*
6161
* Do our own scan, rather than relying on sscanf which might be
62-
* broken for long long. NOTE: this will not detect int64 overflow...
63-
* but sscanf doesn't either...
62+
* broken for long long.
6463
*/
6564
while (*ptr&&isspace(*ptr))/* skip leading spaces */
6665
ptr++;
@@ -69,11 +68,17 @@ int8in(char *str)
6968
elseif (*ptr=='+')
7069
ptr++;
7170
if (!isdigit(*ptr))/* require at least one digit */
72-
elog(ERROR,"Bad int8 external representation'%s'",str);
71+
elog(ERROR,"Bad int8 external representation\"%s\"",str);
7372
while (*ptr&&isdigit(*ptr))/* process digits */
74-
tmp=tmp*10+ (*ptr++-'0');
73+
{
74+
int64newtmp=tmp*10+ (*ptr++-'0');
75+
76+
if ((newtmp /10)!=tmp)/* overflow? */
77+
elog(ERROR,"int8 value out of range: \"%s\"",str);
78+
tmp=newtmp;
79+
}
7580
if (*ptr)/* trailing junk? */
76-
elog(ERROR,"Bad int8 external representation'%s'",str);
81+
elog(ERROR,"Bad int8 external representation\"%s\"",str);
7782

7883
*result= (sign<0) ?-tmp :tmp;
7984

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp