Skip to content

Commit

Permalink
Fix bug with reading from uninitialized memory
Browse files Browse the repository at this point in the history
  • Loading branch information
spkrka committed Sep 4, 2013
1 parent 3412f3c commit d6e3345
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/hashwriter.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ sparkey_returncode sparkey_hash_write(const char *hash_filename, const char *log
uint64_t start;
uint32_t hash_seed;
int copy_old;
uint32_t old_hash_size = 0;
returncode = sparkey_load_hashheader(&old_header, hash_filename);
if (returncode == SPARKEY_SUCCESS &&
old_header.file_identifier == log_header.file_identifier &&
Expand All @@ -386,6 +387,7 @@ sparkey_returncode sparkey_hash_write(const char *hash_filename, const char *log
// Nothing needs to be done - just exit
goto close_iter;
}
old_hash_size = old_header.hash_size;
} else {
cap = log_header.num_puts * 1.3;
start = log_header.header_size;
Expand All @@ -411,7 +413,7 @@ sparkey_returncode sparkey_hash_write(const char *hash_filename, const char *log
} else {
hash_header.address_size = 8;
}
if (old_header.hash_size == 8 || hash_header.hash_capacity >= (1 << 23)) {
if (old_hash_size == 8 || hash_header.hash_capacity >= (1 << 23)) {
hash_header.hash_size = 8;
} else {
hash_header.hash_size = 4;
Expand All @@ -424,7 +426,7 @@ sparkey_returncode sparkey_hash_write(const char *hash_filename, const char *log
goto close_iter;
}
}
if (hash_header.hash_size != old_header.hash_size) {
if (hash_header.hash_size != old_hash_size) {
copy_old = 0;
}
hash_header.hash_algorithm = sparkey_get_hash_algorithm(hash_header.hash_size);
Expand Down

0 comments on commit d6e3345

Please sign in to comment.