diff options
author | Michael Paquier <michael@paquier.xyz> | 2020-02-04 13:56:04 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2020-02-04 13:56:04 +0900 |
commit | 177be9edf4bb966400db7769d61e479aa0fe0201 (patch) | |
tree | 2b076f7315dc85b3ab5f5342195ddb5d72348f63 /src | |
parent | 1c7a0b387d18c517d45e2f6ec7d8b7d1b2d5fe13 (diff) | |
download | postgresql-177be9edf4bb966400db7769d61e479aa0fe0201.tar.gz postgresql-177be9edf4bb966400db7769d61e479aa0fe0201.zip |
Fix fuzzy error handling in pg_basebackup when opening gzFile
First, this code did not bother checking for a failure when calling
dup(). Then, per zlib, gzerror() returns NULL for a NULL input, which
can happen if passing down to gzdopen() an invalid file descriptor or if
there was an allocation failure.
No back-patch is done as this would unlikely be a problem in the field.
Per Coverity.
Reported-by: Tom Lane
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/pg_basebackup/pg_basebackup.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c index 556a0af9160..4e12cdb4467 100644 --- a/src/bin/pg_basebackup/pg_basebackup.c +++ b/src/bin/pg_basebackup/pg_basebackup.c @@ -1022,7 +1022,20 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum) #ifdef HAVE_LIBZ if (compresslevel != 0) { - state.ztarfile = gzdopen(dup(fileno(stdout)), "wb"); + int fd = dup(fileno(stdout)); + if (fd < 0) + { + pg_log_error("could not duplicate stdout: %m"); + exit(1); + } + + state.ztarfile = gzdopen(fd, "wb"); + if (state.ztarfile == NULL) + { + pg_log_error("could not open output file: %m"); + exit(1); + } + if (gzsetparams(state.ztarfile, compresslevel, Z_DEFAULT_STRATEGY) != Z_OK) { |