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

Commit5df44d1

Browse files
committed
pgbench: avoid FD_ISSET on an invalid file descriptor
The original code wasn't careful to test the file descriptor returned byPQsocket() for an invalid socket. If an invalid socket did turn up,that would amount to calling FD_ISSET with fd = -1, whereby undefinedbehavior can be invoked.To fix, test file descriptor for validity and stop further processing ifthat fails.Problem noticed by Coverity.There is an existing FD_ISSET callsite that does check for invalidsockets beforehand, but the error message reported by it wasstrerror(errno); in testing the aforementioned change, that turns out toresult in "bad socket: Success" which isn't terribly helpful. Insteaduse PQerrorMessage() in both places which is more likely to contain anuseful error message.Backpatch-through: 9.1.
1 parent8c95ae8 commit5df44d1

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

‎src/bin/pgbench/pgbench.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3706,7 +3706,7 @@ threadRun(void *arg)
37063706
sock=PQsocket(st->con);
37073707
if (sock<0)
37083708
{
3709-
fprintf(stderr,"bad socket: %s\n",strerror(errno));
3709+
fprintf(stderr,"bad socket: %s",PQerrorMessage(st->con));
37103710
gotodone;
37113711
}
37123712

@@ -3770,11 +3770,21 @@ threadRun(void *arg)
37703770
Command**commands=sql_script[st->use_file].commands;
37713771
intprev_ecnt=st->ecnt;
37723772

3773-
if (st->con&& (FD_ISSET(PQsocket(st->con),&input_mask)
3774-
||commands[st->state]->type==META_COMMAND))
3773+
if (st->con)
37753774
{
3776-
if (!doCustom(thread,st,&aggs))
3777-
remains--;/* I've aborted */
3775+
intsock=PQsocket(st->con);
3776+
3777+
if (sock<0)
3778+
{
3779+
fprintf(stderr,"bad socket: %s",PQerrorMessage(st->con));
3780+
gotodone;
3781+
}
3782+
if (FD_ISSET(sock,&input_mask)||
3783+
commands[st->state]->type==META_COMMAND)
3784+
{
3785+
if (!doCustom(thread,st,&aggs))
3786+
remains--;/* I've aborted */
3787+
}
37783788
}
37793789

37803790
if (st->ecnt>prev_ecnt&&commands[st->state]->type==META_COMMAND)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp