mirror of
https://github.com/postgres/postgres.git
synced 2025-06-07 11:02:12 +03:00
Fix some pg_verifybackup issues reported by Coverity.
Commit 8dfd3129027969fdd2d9d294220c867d2efd84aa 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
This commit is contained in:
parent
9c2a6c5a5f
commit
fc1b2ce0ee
@ -341,14 +341,14 @@ member_copy_control_data(astreamer *streamer, astreamer_member *member,
|
|||||||
* be PG_CONTROL_FILE_SIZE, but the part that fits in our buffer is
|
* be PG_CONTROL_FILE_SIZE, but the part that fits in our buffer is
|
||||||
* shorter, just sizeof(ControlFileData).
|
* shorter, just sizeof(ControlFileData).
|
||||||
*/
|
*/
|
||||||
if (mystreamer->control_file_bytes <= sizeof(ControlFileData))
|
if (mystreamer->control_file_bytes < sizeof(ControlFileData))
|
||||||
{
|
{
|
||||||
int remaining;
|
size_t remaining;
|
||||||
|
|
||||||
remaining = sizeof(ControlFileData) - mystreamer->control_file_bytes;
|
remaining = sizeof(ControlFileData) - mystreamer->control_file_bytes;
|
||||||
memcpy(((char *) &mystreamer->control_file)
|
memcpy(((char *) &mystreamer->control_file)
|
||||||
+ mystreamer->control_file_bytes,
|
+ mystreamer->control_file_bytes,
|
||||||
data, Min(len, remaining));
|
data, Min((size_t) len, remaining));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remember how many bytes we saw, even if we didn't buffer them. */
|
/* Remember how many bytes we saw, even if we didn't buffer them. */
|
||||||
|
@ -929,9 +929,12 @@ precheck_tar_backup_file(verifier_context *context, char *relpath,
|
|||||||
* result is 0, or if the value is too large to be a valid OID.
|
* result is 0, or if the value is too large to be a valid OID.
|
||||||
*/
|
*/
|
||||||
if (suffix == NULL || num <= 0 || num > OID_MAX)
|
if (suffix == NULL || num <= 0 || num > OID_MAX)
|
||||||
|
{
|
||||||
report_backup_error(context,
|
report_backup_error(context,
|
||||||
"file \"%s\" is not expected in a tar format backup",
|
"file \"%s\" is not expected in a tar format backup",
|
||||||
relpath);
|
relpath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
tblspc_oid = (Oid) num;
|
tblspc_oid = (Oid) num;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1014,6 +1017,8 @@ verify_tar_file(verifier_context *context, char *relpath, char *fullpath,
|
|||||||
progress_report(false);
|
progress_report(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pg_free(buffer);
|
||||||
|
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
report_backup_error(context, "could not read file \"%s\": %m",
|
report_backup_error(context, "could not read file \"%s\": %m",
|
||||||
relpath);
|
relpath);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user