Skip to content

Commit 177be9e

Browse files
committed
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
1 parent 1c7a0b3 commit 177be9e

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,20 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
10221022
#ifdef HAVE_LIBZ
10231023
if (compresslevel != 0)
10241024
{
1025-
state.ztarfile = gzdopen(dup(fileno(stdout)), "wb");
1025+
int fd = dup(fileno(stdout));
1026+
if (fd < 0)
1027+
{
1028+
pg_log_error("could not duplicate stdout: %m");
1029+
exit(1);
1030+
}
1031+
1032+
state.ztarfile = gzdopen(fd, "wb");
1033+
if (state.ztarfile == NULL)
1034+
{
1035+
pg_log_error("could not open output file: %m");
1036+
exit(1);
1037+
}
1038+
10261039
if (gzsetparams(state.ztarfile, compresslevel,
10271040
Z_DEFAULT_STRATEGY) != Z_OK)
10281041
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy