Add extra assert() in tests allocating memory on the heap.

This commit is contained in:
Frank Denis 2014-11-25 16:19:20 -08:00
parent 6189eec330
commit d556a56c3c
3 changed files with 5 additions and 0 deletions

View File

@ -267,8 +267,10 @@ static void tv3(void)
do { do {
out = (char *) sodium_malloc(strlen(tests[i].out) + 1U); out = (char *) sodium_malloc(strlen(tests[i].out) + 1U);
assert(out != NULL);
memcpy(out, tests[i].out, strlen(tests[i].out) + 1U); memcpy(out, tests[i].out, strlen(tests[i].out) + 1U);
passwd = (char *) sodium_malloc(strlen(tests[i].passwd) + 1U); passwd = (char *) sodium_malloc(strlen(tests[i].passwd) + 1U);
assert(passwd != NULL);
memcpy(passwd, tests[i].passwd, strlen(tests[i].passwd) + 1U); memcpy(passwd, tests[i].passwd, strlen(tests[i].passwd) + 1U);
if (crypto_pwhash_scryptsalsa208sha256_str_verify( if (crypto_pwhash_scryptsalsa208sha256_str_verify(
out, passwd, strlen(passwd)) != 0) { out, passwd, strlen(passwd)) != 0) {

View File

@ -48,6 +48,7 @@ int main(void)
for (i = 0U; i < 10000U; i++) { for (i = 0U; i < 10000U; i++) {
size = randombytes_uniform(100000U); size = randombytes_uniform(100000U);
buf = sodium_malloc(size); buf = sodium_malloc(size);
assert(buf != NULL);
memset(buf, i, size); memset(buf, i, size);
sodium_mprotect_readonly(buf); sodium_mprotect_readonly(buf);
sodium_free(buf); sodium_free(buf);
@ -65,6 +66,7 @@ int main(void)
#endif #endif
size = randombytes_uniform(100000U); size = randombytes_uniform(100000U);
buf = sodium_malloc(size); buf = sodium_malloc(size);
assert(buf != NULL);
sodium_mprotect_readonly(buf); sodium_mprotect_readonly(buf);
sodium_mprotect_readwrite(buf); sodium_mprotect_readwrite(buf);
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__

View File

@ -43,6 +43,7 @@ int main(void)
#endif #endif
size = randombytes_uniform(100000U); size = randombytes_uniform(100000U);
buf = sodium_malloc(size); buf = sodium_malloc(size);
assert(buf != NULL);
sodium_mprotect_noaccess(buf); sodium_mprotect_noaccess(buf);
sodium_mprotect_readwrite(buf); sodium_mprotect_readwrite(buf);
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__