[PATCH] Fix possible Uninitialized variables (parse_manifest.c)
Started by Ranier Vilelaover 5 years ago1 messages
Hi,
Per Coverity.
verify_manifest_checksum, declare and can utilize array of uint8, without
initializing it.
While here, I applied the quick exit technique, to avoid unnecessary
computations, if it is possible to avoid them.
regards,
Ranier Vilela
Attachments:
fix_uninitialized_array_parse_manifest.patchapplication/octet-stream; name=fix_uninitialized_array_parse_manifest.patchDownload
diff --git a/src/bin/pg_verifybackup/parse_manifest.c b/src/bin/pg_verifybackup/parse_manifest.c
index faee423c7e..71c0a96e51 100644
--- a/src/bin/pg_verifybackup/parse_manifest.c
+++ b/src/bin/pg_verifybackup/parse_manifest.c
@@ -628,6 +628,17 @@ verify_manifest_checksum(JsonManifestParseState *parse, char *buffer,
uint8 manifest_checksum_actual[PG_SHA256_DIGEST_LENGTH];
uint8 manifest_checksum_expected[PG_SHA256_DIGEST_LENGTH];
+ /* Verify checksum validate before (quick exit) */
+ if (parse->manifest_checksum == NULL)
+ context->error_cb(parse->context, "manifest has no checksum");
+ if (strlen(parse->manifest_checksum) != PG_SHA256_DIGEST_LENGTH * 2)
+ context->error_cb(context, "invalid manifest checksum: \"%s\"",
+ parse->manifest_checksum);
+ if (!hexdecode_string(manifest_checksum_expected, parse->manifest_checksum,
+ PG_SHA256_DIGEST_LENGTH))
+ context->error_cb(context, "invalid manifest checksum: \"%s\"",
+ parse->manifest_checksum);
+
/* Find the last two newlines in the file. */
for (i = 0; i < size; ++i)
{
@@ -657,13 +668,6 @@ verify_manifest_checksum(JsonManifestParseState *parse, char *buffer,
pg_sha256_final(&manifest_ctx, manifest_checksum_actual);
/* Now verify it. */
- if (parse->manifest_checksum == NULL)
- context->error_cb(parse->context, "manifest has no checksum");
- if (strlen(parse->manifest_checksum) != PG_SHA256_DIGEST_LENGTH * 2 ||
- !hexdecode_string(manifest_checksum_expected, parse->manifest_checksum,
- PG_SHA256_DIGEST_LENGTH))
- context->error_cb(context, "invalid manifest checksum: \"%s\"",
- parse->manifest_checksum);
if (memcmp(manifest_checksum_actual, manifest_checksum_expected,
PG_SHA256_DIGEST_LENGTH) != 0)
context->error_cb(context, "manifest checksum mismatch");