Skip to content

Commit 76dd015

Browse files
committed
Improve more comments in astreamer_gzip.c.
Duplicate the comment from astreamer_plain_writer_new instead of just referring to it. Add a further note to mention that there are dangers if anything else is written to the same FILE. Also add a comment where we dup() the filehandle, referring to the existing comment in astreamer_gzip_writer_finalize(), because the dup() looks wrong on first glance without that comment to clarify. Per concerns expressed by Tom Lane on pgsql-security, and using some wording suggested by him. Discussion: http://postgr.es/m/CA+TgmoYTFAD0YTh4HC1Nuhn0YEyoQi0_CENFgVzAY_YReiSksQ@mail.gmail.com
1 parent b8b3f86 commit 76dd015

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/fe_utils/astreamer_gzip.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,16 @@ static const astreamer_ops astreamer_gzip_decompressor_ops = {
8686
* Create a astreamer that just compresses data using gzip, and then writes
8787
* it to a file.
8888
*
89-
* As in the case of astreamer_plain_writer_new, pathname is always used
90-
* for error reporting purposes; if file is NULL, it is also the opened and
91-
* closed so that the data may be written there.
89+
* The caller must specify a pathname and may specify a file. The pathname is
90+
* used for error-reporting purposes either way. If file is NULL, the pathname
91+
* also identifies the file to which the data should be written: it is opened
92+
* for writing and closed when done. If file is not NULL, the data is written
93+
* there.
94+
*
95+
* Note that zlib does not use the FILE interface, but operates directly on
96+
* a duplicate of the underlying fd. Hence, callers must take care if they
97+
* plan to write any other data to the same FILE, either before or after using
98+
* this.
9299
*/
93100
astreamer *
94101
astreamer_gzip_writer_new(char *pathname, FILE *file,
@@ -112,6 +119,10 @@ astreamer_gzip_writer_new(char *pathname, FILE *file,
112119
}
113120
else
114121
{
122+
/*
123+
* We must dup the file handle so that gzclose doesn't break the
124+
* caller's FILE. See comment for astreamer_gzip_writer_finalize.
125+
*/
115126
int fd = dup(fileno(file));
116127

117128
if (fd < 0)

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