innocuous: pgbench does FD_ISSET on invalid socket

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: innocuous: pgbench does FD_ISSET on invalid socket
Date: 2016-02-12 21:25:02
Message-ID: 20160212212502.GA590606@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jim Nasby 2016-02-12 21:41:45 Re: proposal: schema PL session variables
Previous Message Pavel Stehule 2016-02-12 20:58:07 Re: proposal: schema PL session variables