innocuous: pgbench does FD_ISSET on invalid socket - Mailing list pgsql-hackers

From Alvaro Herrera
Subject innocuous: pgbench does FD_ISSET on invalid socket
Date
Msg-id 20160212212502.GA590606@alvherre.pgsql
Whole thread Raw
Responses Re: innocuous: pgbench does FD_ISSET on invalid socket
Re: innocuous: pgbench does FD_ISSET on invalid socket
List pgsql-hackers
I noticed that pgbench calls FD_ISSET on a socket returned by
PQsocket() without first checking that it's not invalid.  I don't think
there's a real problem here because the socket was already checked a few
lines above, but I think applying the same coding pattern to both places
is cleaner.

Any objections to changing it like this?  I'd probably backpatch to 9.5,
but no further (even though this pattern actually appears all the way
back.)

*** a/src/bin/pgbench/pgbench.c
--- b/src/bin/pgbench/pgbench.c
***************
*** 3770,3780 **** threadRun(void *arg)             Command   **commands = sql_script[st->use_file].commands;
 int            prev_ecnt = st->ecnt; 
 
!             if (st->con && (FD_ISSET(PQsocket(st->con), &input_mask)
!                             || commands[st->state]->type == META_COMMAND))             {
!                 if (!doCustom(thread, st, &aggs))
!                     remains--;    /* I've aborted */             }              if (st->ecnt > prev_ecnt &&
commands[st->state]->type== META_COMMAND)
 
--- 3770,3790 ----             Command   **commands = sql_script[st->use_file].commands;             int
prev_ecnt= st->ecnt; 
 
!             if (st->con)             {
!                 int        sock = PQsocket(st->con);
! 
!                 if (sock < 0)
!                 {
!                     fprintf(stderr, "bad socket: %s\n", strerror(errno));
!                     goto done;
!                 }
!                 if (FD_ISSET(sock, &input_mask) ||
!                     commands[st->state]->type == META_COMMAND)
!                 {
!                     if (!doCustom(thread, st, &aggs))
!                         remains--;    /* I've aborted */
!                 }             }              if (st->ecnt > prev_ecnt && commands[st->state]->type == META_COMMAND)

-- 
Álvaro Herrera                            http://www.linkedin.com/in/alvherre



pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: proposal: schema PL session variables
Next
From: Jim Nasby
Date:
Subject: Re: proposal: schema PL session variables