Skip to content

Commit fc1b2ce

Browse files
committed
Fix some pg_verifybackup issues reported by Coverity.
Commit 8dfd312 introduced a few problems. verify_tar_file() forgot to free a buffer; the leak can't add up to anything material, but might as well fix it. precheck_tar_backup_file() intended to return after reporting an error but didn't actually do so. member_copy_control_data() could try to copy zero bytes (and maybe Coverity thinks it can even be trying to copy a negative number of bytes). Per discussion with Tom Lane. Discussion: http://postgr.es/m/1240823.1727629418@sss.pgh.pa.us
1 parent 9c2a6c5 commit fc1b2ce

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/bin/pg_verifybackup/astreamer_verify.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,14 +341,14 @@ member_copy_control_data(astreamer *streamer, astreamer_member *member,
341341
* be PG_CONTROL_FILE_SIZE, but the part that fits in our buffer is
342342
* shorter, just sizeof(ControlFileData).
343343
*/
344-
if (mystreamer->control_file_bytes <= sizeof(ControlFileData))
344+
if (mystreamer->control_file_bytes < sizeof(ControlFileData))
345345
{
346-
int remaining;
346+
size_t remaining;
347347

348348
remaining = sizeof(ControlFileData) - mystreamer->control_file_bytes;
349349
memcpy(((char *) &mystreamer->control_file)
350350
+ mystreamer->control_file_bytes,
351-
data, Min(len, remaining));
351+
data, Min((size_t) len, remaining));
352352
}
353353

354354
/* Remember how many bytes we saw, even if we didn't buffer them. */

src/bin/pg_verifybackup/pg_verifybackup.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,9 +929,12 @@ precheck_tar_backup_file(verifier_context *context, char *relpath,
929929
* result is 0, or if the value is too large to be a valid OID.
930930
*/
931931
if (suffix == NULL || num <= 0 || num > OID_MAX)
932+
{
932933
report_backup_error(context,
933934
"file \"%s\" is not expected in a tar format backup",
934935
relpath);
936+
return;
937+
}
935938
tblspc_oid = (Oid) num;
936939
}
937940

@@ -1014,6 +1017,8 @@ verify_tar_file(verifier_context *context, char *relpath, char *fullpath,
10141017
progress_report(false);
10151018
}
10161019

1020+
pg_free(buffer);
1021+
10171022
if (rc < 0)
10181023
report_backup_error(context, "could not read file \"%s\": %m",
10191024
relpath);

0 commit comments

Comments
 (0)