pgsql: pgbench: avoid FD_ISSET on an invalid file descriptor

Поиск
Список
Период
Сортировка
От Alvaro Herrera
Тема pgsql: pgbench: avoid FD_ISSET on an invalid file descriptor
Дата
Msg-id E1aVShi-0006RN-B5@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
pgbench: avoid FD_ISSET on an invalid file descriptor

The original code wasn't careful to test the file descriptor returned by
PQsocket() for an invalid socket.  If an invalid socket did turn up,
that would amount to calling FD_ISSET with fd = -1, whereby undefined
behavior can be invoked.

To fix, test file descriptor for validity and stop further processing if
that fails.

Problem noticed by Coverity.

There is an existing FD_ISSET callsite that does check for invalid
sockets beforehand, but the error message reported by it was
strerror(errno); in testing the aforementioned change, that turns out to
result in "bad socket: Success" which isn't terribly helpful.  Instead
use PQerrorMessage() in both places which is more likely to contain an
useful error message.

Backpatch-through: 9.1.

Branch
------
REL9_3_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/baa7f635367e0e66f8bdb1998fb99d6f47203b1c

Modified Files
--------------
contrib/pgbench/pgbench.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: pgsql: pgbench: avoid FD_ISSET on an invalid file descriptor
Следующее
От: Andres Freund
Дата:
Сообщение: pgsql: Allow the WAL writer to flush WAL at a reduced rate.