Fix stack corruption and uninitialized var warning

Stack corruption happens in x64 bit

This resolves #347.
This commit is contained in:
Dmitri Smirnov 2016-02-29 14:30:19 -08:00 committed by Jason Evans
parent 0e1d5c25c6
commit 33184bf698
2 changed files with 8 additions and 7 deletions

View File

@ -2423,7 +2423,7 @@ arena_malloc_large(tsd_t *tsd, arena_t *arena, szind_t binind, bool zero)
uintptr_t random_offset; uintptr_t random_offset;
arena_run_t *run; arena_run_t *run;
arena_chunk_map_misc_t *miscelm; arena_chunk_map_misc_t *miscelm;
UNUSED bool idump; UNUSED bool idump JEMALLOC_CC_SILENCE_INIT(false);
/* Large allocation. */ /* Large allocation. */
usize = index2size(binind); usize = index2size(binind);

View File

@ -64,14 +64,15 @@ static void
hash_variant_verify_key(hash_variant_t variant, uint8_t *key) hash_variant_verify_key(hash_variant_t variant, uint8_t *key)
{ {
const int hashbytes = hash_variant_bits(variant) / 8; const int hashbytes = hash_variant_bits(variant) / 8;
VARIABLE_ARRAY(uint8_t, hashes, hashbytes * 256); const int hashes_size = hashbytes * 256;
VARIABLE_ARRAY(uint8_t, hashes, hashes_size);
VARIABLE_ARRAY(uint8_t, final, hashbytes); VARIABLE_ARRAY(uint8_t, final, hashbytes);
unsigned i; unsigned i;
uint32_t computed, expected; uint32_t computed, expected;
memset(key, 0, KEY_SIZE); memset(key, 0, KEY_SIZE);
memset(hashes, 0, sizeof(hashes)); memset(hashes, 0, hashes_size);
memset(final, 0, sizeof(final)); memset(final, 0, hashbytes);
/* /*
* Hash keys of the form {0}, {0,1}, {0,1,2}, ..., {0,1,...,255} as the * Hash keys of the form {0}, {0,1}, {0,1,2}, ..., {0,1,...,255} as the
@ -102,17 +103,17 @@ hash_variant_verify_key(hash_variant_t variant, uint8_t *key)
/* Hash the result array. */ /* Hash the result array. */
switch (variant) { switch (variant) {
case hash_variant_x86_32: { case hash_variant_x86_32: {
uint32_t out = hash_x86_32(hashes, hashbytes*256, 0); uint32_t out = hash_x86_32(hashes, hashes_size, 0);
memcpy(final, &out, sizeof(out)); memcpy(final, &out, sizeof(out));
break; break;
} case hash_variant_x86_128: { } case hash_variant_x86_128: {
uint64_t out[2]; uint64_t out[2];
hash_x86_128(hashes, hashbytes*256, 0, out); hash_x86_128(hashes, hashes_size, 0, out);
memcpy(final, out, sizeof(out)); memcpy(final, out, sizeof(out));
break; break;
} case hash_variant_x64_128: { } case hash_variant_x64_128: {
uint64_t out[2]; uint64_t out[2];
hash_x64_128(hashes, hashbytes*256, 0, out); hash_x64_128(hashes, hashes_size, 0, out);
memcpy(final, out, sizeof(out)); memcpy(final, out, sizeof(out));
break; break;
} default: not_reached(); } default: not_reached();