postgresql/src/bin
Tom Lane 3cac2c8caa Handle close() failures more robustly in pg_dump and pg_basebackup.
Coverity complained that applying get_gz_error after a failed gzclose,
as we did in one place in pg_basebackup, is unsafe.  I think it's
right: it's entirely likely that the call is touching freed memory.
Change that to inspect errno, as we do for other gzclose calls.

Also, be careful to initialize errno to zero immediately before any
gzclose() call where we care about the error status.  (There are
some calls where we don't, because we already failed at some previous
step.)  This ensures that we don't get a misleadingly irrelevant
error code if gzclose() fails in a way that doesn't set errno.
We could work harder at that, but it looks to me like all such cases
are basically can't-happen if we're not misusing zlib, so it's
not worth the extra notational cruft that would be required.

Also, fix several places that simply failed to check for close-time
errors at all, mostly at some remove from the close or gzclose itself;
and one place that did check but didn't bother to report the errno.

Back-patch to v12.  These mistakes are older than that, but between
the frontend logging API changes that happened in v12 and the fact
that frontend code can't rely on %m before that, the patch would need
substantial revision to work in older branches.  It doesn't quite
seem worth the trouble given the lack of related field complaints.

Patch by me; thanks to Michael Paquier for review.

Discussion: https://postgr.es/m/1343113.1636489231@sss.pgh.pa.us
2021-11-17 13:08:25 -05:00
..
initdb Fix incorrect format placeholder 2021-11-03 07:34:28 +01:00
pg_amcheck Remove tests added by bd807be693. 2021-11-07 15:32:32 -05:00
pg_archivecleanup Move Perl test modules to a better namespace 2021-10-24 10:28:19 -04:00
pg_basebackup Handle close() failures more robustly in pg_dump and pg_basebackup. 2021-11-17 13:08:25 -05:00
pg_checksums Move Perl test modules to a better namespace 2021-10-24 10:28:19 -04:00
pg_config Move Perl test modules to a better namespace 2021-10-24 10:28:19 -04:00
pg_controldata Move Perl test modules to a better namespace 2021-10-24 10:28:19 -04:00
pg_ctl Move Perl test modules to a better namespace 2021-10-24 10:28:19 -04:00
pg_dump Handle close() failures more robustly in pg_dump and pg_basebackup. 2021-11-17 13:08:25 -05:00
pg_resetwal Move Perl test modules to a better namespace 2021-10-24 10:28:19 -04:00
pg_rewind Move Perl test modules to a better namespace 2021-10-24 10:28:19 -04:00
pg_test_fsync Move Perl test modules to a better namespace 2021-10-24 10:28:19 -04:00
pg_test_timing Move Perl test modules to a better namespace 2021-10-24 10:28:19 -04:00
pg_upgrade Fix tests of pg_upgrade across different major versions 2021-10-13 09:22:00 +09:00
pg_verifybackup Move Perl test modules to a better namespace 2021-10-24 10:28:19 -04:00
pg_waldump Move Perl test modules to a better namespace 2021-10-24 10:28:19 -04:00
pgbench pgbench: Fix typo in comment. 2021-11-02 23:08:02 +09:00
pgevent Update copyright for 2021 2021-01-02 13:06:25 -05:00
psql Make psql's \password default to CURRENT_USER, not PQuser(conn). 2021-11-12 14:55:32 -05:00
scripts Clarify that --system reindexes system catalogs *only* 2021-10-27 16:28:11 +02:00
Makefile Add pg_amcheck, a CLI for contrib/amcheck. 2021-03-12 13:00:01 -05:00