diff options
Diffstat (limited to 'c_src/permdb.c')
-rw-r--r-- | c_src/permdb.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/c_src/permdb.c b/c_src/permdb.c index 57a09d3..bada31f 100644 --- a/c_src/permdb.c +++ b/c_src/permdb.c @@ -349,6 +349,7 @@ verify_index_commit(buffered_file *file, node_offset offset) if (memcmp(data + sizeof(uint64_t) + SHA256_DIGEST_SIZE, &index_commit_cookie, sizeof(index_commit_cookie)) != 0) { fprintf(stderr, "verifying index file: incorrect commit cookie\n"); + free(data); return -1; } struct commit_info commit; @@ -358,6 +359,7 @@ verify_index_commit(buffered_file *file, node_offset offset) commit.start = offset - commit.length; memcpy(commit.checksum, data + sizeof(uint64_t), SHA256_DIGEST_SIZE); + free(data); return validate_checksum(&commit, file); } @@ -386,7 +388,7 @@ int datafile_verify_file(buffered_file *file) { unsigned char *header = read_from_file(file, sizeof(data_file_cookie), 0); - if (memcmp(header, &data_file_cookie, sizeof(data_file_cookie)) != 0) { + if (header == NULL || memcmp(header, &data_file_cookie, sizeof(data_file_cookie)) != 0) { free(header); return -1; } @@ -416,7 +418,8 @@ struct commit_info * read_data_commit(buffered_file *file, node_offset *offset) { unsigned char *data = read_from_file(file, sizeof(uint32_t) + SHA256_DIGEST_SIZE + sizeof(data_commit_end_cookie), *offset); - if (memcmp(data + sizeof(uint32_t) + SHA256_DIGEST_SIZE, data_commit_end_cookie, sizeof(data_commit_end_cookie)) != 0) { + if (data == NULL || memcmp(data + sizeof(uint32_t) + SHA256_DIGEST_SIZE, data_commit_end_cookie, sizeof(data_commit_end_cookie)) != 0) { + free(data); return NULL; } *offset += sizeof(uint32_t); @@ -427,6 +430,7 @@ read_data_commit(buffered_file *file, node_offset *offset) commit->start = *offset - commit->length; memcpy(&commit->checksum, data + sizeof(uint32_t), SHA256_DIGEST_SIZE); *offset += SHA256_DIGEST_SIZE + sizeof(data_commit_end_cookie); + free(data); return commit; } |