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

Commit68cbb9f

Browse files
committed
Modestly improve pgbench's checking for invalid ranges.
The old check against MAX_RANDOM_VALUE is clearly irrelevant sincegetrand() no longer calls random(). Instead, check whether min and maxare close enough together to avoid an overflow inside getrand(), assuggested by Tom Lane. This is still somewhat silly, because we'reusing atoi(), which doesn't check for overflow anyway and (at least onmy system) will cheerfully return 0 when given "4294967296". But that'sa problem for another commit.
1 parentb43bf61 commit68cbb9f

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

‎contrib/pgbench/pgbench.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,9 +1066,23 @@ doCustom(TState *thread, CState *st, instr_time *conn_time, FILE *logfile)
10661066
else
10671067
max=atoi(argv[3]);
10681068

1069-
if (max<min||max>MAX_RANDOM_VALUE)
1069+
if (max<min)
10701070
{
1071-
fprintf(stderr,"%s: invalid maximum number %d\n",argv[0],max);
1071+
fprintf(stderr,"%s: maximum is less than minimum\n",argv[0]);
1072+
st->ecnt++;
1073+
return true;
1074+
}
1075+
1076+
/*
1077+
* getrand() neeeds to be able to subtract max from min and add
1078+
* one the result without overflowing. Since we know max > min,
1079+
* we can detect overflow just by checking for a negative result.
1080+
* But we must check both that the subtraction doesn't overflow,
1081+
* and that adding one to the result doesn't overflow either.
1082+
*/
1083+
if (max-min<0|| (max-min)+1<0)
1084+
{
1085+
fprintf(stderr,"%s: range too large\n",argv[0]);
10721086
st->ecnt++;
10731087
return true;
10741088
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp