diff options
author | Robert Haas | 2024-01-11 18:06:10 +0000 |
---|---|---|
committer | Robert Haas | 2024-01-11 18:06:10 +0000 |
commit | 3d5c332a3d6002c5c95cb238e2164ae054c8e805 (patch) | |
tree | 5308b9922e851faebec1d3f963d7d91c7f315da5 /src/bin/pg_combinebackup/write_manifest.c | |
parent | ee1bfd168390bc843c6704d16e909692c0a79f27 (diff) |
Repair various defects in dc212340058b4e7ecfc5a7a81ec50e7a207bf288.
pg_combinebackup had various problems:
* strncpy was used in various places where strlcpy should be used
instead, to avoid any possibility of the result not being
\0-terminated.
* scan_for_existing_tablespaces() failed to close the directory,
and an error when opening the directory was reported with the
wrong pathname.
* write_reconstructed_file() contained some redundant and therefore
dead code.
* flush_manifest() didn't check the result of pg_checksum_update()
as we do in other places, and misused a local pathname variable
that shouldn't exist at all.
In pg_basebackup, the wrong variable name was used in one place,
due to a copy and paste that was not properly adjusted.
In blkreftable.c, the loop incorrectly doubled chunkno instead of
max_chunks. Fix that. Also remove a nearby assertion per repeated
off-list complaints from Tom Lane.
Per Coverity and subsequent code inspection by me and by Tom Lane.
Discussion: http://postgr.es/m/CA+Tgmobvqqj-DW9F7uUzT-cQqs6wcVb-Xhs=w=hzJnXSE-kRGw@mail.gmail.com
Diffstat (limited to 'src/bin/pg_combinebackup/write_manifest.c')
-rw-r--r-- | src/bin/pg_combinebackup/write_manifest.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/bin/pg_combinebackup/write_manifest.c b/src/bin/pg_combinebackup/write_manifest.c index 608e84f3b45..01deb82cc9f 100644 --- a/src/bin/pg_combinebackup/write_manifest.c +++ b/src/bin/pg_combinebackup/write_manifest.c @@ -241,8 +241,6 @@ escape_json(StringInfo buf, const char *str) static void flush_manifest(manifest_writer *mwriter) { - char pathname[MAXPGPATH]; - if (mwriter->fd == -1 && (mwriter->fd = open(mwriter->pathname, O_WRONLY | O_CREAT | O_EXCL | PG_BINARY, @@ -260,13 +258,15 @@ flush_manifest(manifest_writer *mwriter) pg_fatal("could not write \"%s\": %m", mwriter->pathname); else pg_fatal("could not write file \"%s\": wrote only %d of %d bytes", - pathname, (int) wb, mwriter->buf.len); + mwriter->pathname, (int) wb, mwriter->buf.len); } - if (mwriter->still_checksumming) + if (mwriter->still_checksumming && pg_checksum_update(&mwriter->manifest_ctx, (uint8 *) mwriter->buf.data, - mwriter->buf.len); + mwriter->buf.len) < 0) + pg_fatal("could not update checksum of file \"%s\"", + mwriter->pathname); resetStringInfo(&mwriter->buf); } } |