Skip to content

Commit

Permalink
test/evp_test.c: Add check for OPENSSL_strdup
Browse files Browse the repository at this point in the history
As the potential failure of the OPENSSL_strdup(),
it should be better to check the return value and
return error if fails.

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from #18592)

(cherry picked from commit 5203a8d)
  • Loading branch information
JiangJias authored and paulidale committed Jun 22, 2022
1 parent a58978f commit 6408e7c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions test/evp_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ static int mac_test_parse(EVP_TEST *t,
return parse_bin(value, &mdata->salt, &mdata->salt_len);
if (strcmp(keyword, "Algorithm") == 0) {
mdata->alg = OPENSSL_strdup(value);
if (!mdata->alg)
if (mdata->alg == NULL)
return -1;
return 1;
}
Expand All @@ -1248,9 +1248,13 @@ static int mac_test_parse(EVP_TEST *t,
return mdata->xof = 1;
if (strcmp(keyword, "NoReinit") == 0)
return mdata->no_reinit = 1;
if (strcmp(keyword, "Ctrl") == 0)
return sk_OPENSSL_STRING_push(mdata->controls,
OPENSSL_strdup(value)) != 0;
if (strcmp(keyword, "Ctrl") == 0) {
char *data = OPENSSL_strdup(value);

if (data == NULL)
return -1;
return sk_OPENSSL_STRING_push(mdata->controls, data) != 0;
}
if (strcmp(keyword, "OutputSize") == 0) {
mdata->output_size = atoi(value);
if (mdata->output_size < 0)
Expand Down

0 comments on commit 6408e7c

Please sign in to comment.