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


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to