From 192fd92cc719c287738a02eb531219232359c343 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sat, 16 Dec 2017 14:53:01 +0100 Subject: [PATCH] Plug memory leaks in the pwhash_argon2* tests --- test/default/pwhash_argon2i.c | 11 ++++++----- test/default/pwhash_argon2id.c | 12 ++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/test/default/pwhash_argon2i.c b/test/default/pwhash_argon2i.c index fa811b88..3e1195e1 100644 --- a/test/default/pwhash_argon2i.c +++ b/test/default/pwhash_argon2i.c @@ -208,6 +208,7 @@ tv3(void) char *out; char *passwd; size_t i = 0U; + int ret; do { out = (char *) sodium_malloc(strlen(tests[i].out) + 1U); @@ -216,13 +217,13 @@ tv3(void) passwd = (char *) sodium_malloc(strlen(tests[i].passwd) + 1U); assert(passwd != NULL); memcpy(passwd, tests[i].passwd, strlen(tests[i].passwd) + 1U); - if (crypto_pwhash_str_verify(out, passwd, strlen(passwd)) != 0) { - printf("[tv3] pwhash_str failure (maybe intentional): [%u]\n", - (unsigned int) i); - continue; - } + ret = crypto_pwhash_str_verify(out, passwd, strlen(passwd)); sodium_free(out); sodium_free(passwd); + if (ret != 0) { + printf("[tv3] pwhash_str failure (maybe intentional): [%u]\n", + (unsigned int) i); + } } while (++i < (sizeof tests) / (sizeof tests[0])); } diff --git a/test/default/pwhash_argon2id.c b/test/default/pwhash_argon2id.c index cbb982fa..5940c9ca 100644 --- a/test/default/pwhash_argon2id.c +++ b/test/default/pwhash_argon2id.c @@ -204,6 +204,7 @@ tv3(void) char *out; char *passwd; size_t i = 0U; + int ret; do { out = (char *) sodium_malloc(strlen(tests[i].out) + 1U); @@ -212,13 +213,13 @@ tv3(void) passwd = (char *) sodium_malloc(strlen(tests[i].passwd) + 1U); assert(passwd != NULL); memcpy(passwd, tests[i].passwd, strlen(tests[i].passwd) + 1U); - if (crypto_pwhash_str_verify(out, passwd, strlen(passwd)) != 0) { - printf("[tv3] pwhash_argon2id_str failure (maybe intentional): [%u]\n", - (unsigned int) i); - continue; - } + ret = crypto_pwhash_str_verify(out, passwd, strlen(passwd)); sodium_free(out); sodium_free(passwd); + if (ret != 0) { + printf("[tv3] pwhash_argon2id_str failure (maybe intentional): [%u]\n", + (unsigned int) i); + } } while (++i < (sizeof tests) / (sizeof tests[0])); } @@ -230,7 +231,6 @@ str_tests(void) char *salt; const char *passwd = "Correct Horse Battery Staple"; - salt = (char *) sodium_malloc(crypto_pwhash_argon2id_SALTBYTES); str_out = (char *) sodium_malloc(crypto_pwhash_argon2id_STRBYTES); str_out2 = (char *) sodium_malloc(crypto_pwhash_argon2id_STRBYTES);