Plug memory leaks in the pwhash_argon2* tests

This commit is contained in:
Frank Denis
2017-12-16 14:53:01 +01:00
parent afbef83c6b
commit 192fd92cc7
2 changed files with 12 additions and 11 deletions
+6 -5
View File
@@ -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]));
}
+6 -6
View File
@@ -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);