pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Handle close() failures more robustly in pg_dump and pg_baseback
4+ messages / 1 participants
[nested] [flat]

* pgsql: Handle close() failures more robustly in pg_dump and pg_baseback
@ 2021-11-17 18:08  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2021-11-17 18:08 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/6b413b41b45fe0412ee55b29f23ce31ce894fc90

Modified Files
--------------
src/bin/pg_basebackup/pg_basebackup.c | 5 +++--
src/bin/pg_basebackup/receivelog.c    | 7 ++++++-
src/bin/pg_basebackup/walmethods.c    | 3 +++
src/bin/pg_dump/pg_backup_archiver.c  | 2 ++
src/bin/pg_dump/pg_backup_directory.c | 9 ++++++---
src/bin/pg_dump/pg_backup_tar.c       | 5 ++++-
6 files changed, 24 insertions(+), 7 deletions(-)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* pgsql: Handle close() failures more robustly in pg_dump and pg_baseback
@ 2021-11-17 18:08  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2021-11-17 18:08 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/bbda88c3383dd8da07f36f06d34cb876bc4982e7

Modified Files
--------------
src/bin/pg_basebackup/pg_basebackup.c | 5 +++--
src/bin/pg_basebackup/receivelog.c    | 7 ++++++-
src/bin/pg_basebackup/walmethods.c    | 3 +++
src/bin/pg_dump/pg_backup_archiver.c  | 2 ++
src/bin/pg_dump/pg_backup_directory.c | 9 ++++++---
src/bin/pg_dump/pg_backup_tar.c       | 5 ++++-
6 files changed, 24 insertions(+), 7 deletions(-)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* pgsql: Handle close() failures more robustly in pg_dump and pg_baseback
@ 2021-11-17 18:08  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2021-11-17 18:08 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/3cac2c8caaefc642332e6994ce80032cc7d4cfdf

Modified Files
--------------
src/bin/pg_basebackup/bbstreamer_file.c | 6 +++---
src/bin/pg_basebackup/receivelog.c      | 7 ++++++-
src/bin/pg_basebackup/walmethods.c      | 3 +++
src/bin/pg_dump/pg_backup_archiver.c    | 2 ++
src/bin/pg_dump/pg_backup_directory.c   | 9 ++++++---
src/bin/pg_dump/pg_backup_tar.c         | 5 ++++-
6 files changed, 24 insertions(+), 8 deletions(-)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* pgsql: Handle close() failures more robustly in pg_dump and pg_baseback
@ 2021-11-17 18:08  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2021-11-17 18:08 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/12bf118899eb95a9b3afd67ab666698a1019e1e8

Modified Files
--------------
src/bin/pg_basebackup/pg_basebackup.c | 5 +++--
src/bin/pg_basebackup/receivelog.c    | 7 ++++++-
src/bin/pg_basebackup/walmethods.c    | 3 +++
src/bin/pg_dump/pg_backup_archiver.c  | 2 ++
src/bin/pg_dump/pg_backup_directory.c | 9 ++++++---
src/bin/pg_dump/pg_backup_tar.c       | 5 ++++-
6 files changed, 24 insertions(+), 7 deletions(-)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2021-11-17 18:08 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-11-17 18:08 pgsql: Handle close() failures more robustly in pg_dump and pg_baseback Tom Lane <tgl@sss.pgh.pa.us>
2021-11-17 18:08 pgsql: Handle close() failures more robustly in pg_dump and pg_baseback Tom Lane <tgl@sss.pgh.pa.us>
2021-11-17 18:08 pgsql: Handle close() failures more robustly in pg_dump and pg_baseback Tom Lane <tgl@sss.pgh.pa.us>
2021-11-17 18:08 pgsql: Handle close() failures more robustly in pg_dump and pg_baseback Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox