[v2] examples/fips_validation: fix memory leak in sha test
Checks
Commit Message
There is wrong size used for allocation of digest buffer which in
some cases cause memory corruption. Also, fixed places where memory
leak is observed. This fix would enable sha 384 and 512 NIST vectors
be supported fully.
Fixes: 93d797d94f1 ("examples/fips_validation: add parsing for sha")
Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
---
Depends-on: series-23828 ("example/fips_validation: add xts and sha json parsing")
---
doc/guides/sample_app_ug/fips_validation.rst | 2 +-
examples/fips_validation/fips_validation_sha.c | 10 ++++++++--
examples/fips_validation/main.c | 1 +
3 files changed, 10 insertions(+), 3 deletions(-)
Comments
> Subject: [PATCH v2] examples/fips_validation: fix memory leak in sha test
>
> There is wrong size used for allocation of digest buffer which in
> some cases cause memory corruption. Also, fixed places where memory
> leak is observed. This fix would enable sha 384 and 512 NIST vectors
> be supported fully.
>
> Fixes: 93d797d94f1 ("examples/fips_validation: add parsing for sha")
>
> Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
> ---
Applied to dpdk-next-crypto
Thanks.
@@ -63,7 +63,7 @@ ACVP
* AES-CMAC (128,192,256) - AFT
* AES-XTS (128,256) - AFT
* HMAC (SHA1, SHA224, SHA256, SHA384, SHA512)
- * SHA (1,256) - AFT, MCT
+ * SHA (1, 256, 384, 512) - AFT, MCT
Application Information
@@ -229,13 +229,19 @@ parse_test_sha_json_algorithm(void)
for (i = 0; i < RTE_DIM(phsc); i++) {
if (info.interim_info.sha_data.algo == phsc[i].algo) {
vec.cipher_auth.digest.len = atoi(phsc[i].str);
- vec.cipher_auth.digest.val = calloc(0, vec.cipher_auth.digest.len * 8);
+ if (vec.cipher_auth.digest.val)
+ free(vec.cipher_auth.digest.val);
+
+ vec.cipher_auth.digest.val = calloc(1, vec.cipher_auth.digest.len);
break;
}
}
- if (i == RTE_DIM(phsc))
+ if (i == RTE_DIM(phsc)) {
+ free(vec.cipher_auth.digest.val);
+ vec.cipher_auth.digest.val = NULL;
return -1;
+ }
return 0;
}
@@ -2099,6 +2099,7 @@ fips_test_one_json_file(void)
json_info.json_vector_set = json_array_get(json_info.json_root, vector_set_idx);
fips_test_one_vector_set();
json_array_append_new(json_info.json_write_root, json_info.json_write_set);
+ json_incref(json_info.json_write_set);
}
json_dumpf(json_info.json_write_root, info.fp_wr, JSON_INDENT(4));