innocuous: pgbench does FD_ISSET on invalid socket

Поиск
Список
Период
Сортировка
От Alvaro Herrera
Тема innocuous: pgbench does FD_ISSET on invalid socket
Дата
Msg-id 20160212212502.GA590606@alvherre.pgsql
обсуждение исходный текст
Ответы Re: innocuous: pgbench does FD_ISSET on invalid socket  (Michael Paquier <michael.paquier@gmail.com>)
Re: innocuous: pgbench does FD_ISSET on invalid socket  (Fabien COELHO <coelho@cri.ensmp.fr>)
Список 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 по дате отправления:

Предыдущее
От: Pavel Stehule
Дата:
Сообщение: Re: proposal: schema PL session variables
Следующее
От: Jim Nasby
Дата:
Сообщение: Re: proposal: schema PL session variables