DPDK patches and discussions
 help / color / mirror / Atom feed
From: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
To: <dev@dpdk.org>
Cc: Anoob Joseph <anoobj@marvell.com>,
	Fan Zhang <roy.fan.zhang@intel.com>,
	Brian Dooley <brian.dooley@intel.com>,
	Akhil Goyal <gakhil@marvell.com>, <jerinj@marvell.com>,
	Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
Subject: [v2 4/7] examples/fips_validation: fix buffer size to parse JSON string
Date: Tue, 27 Sep 2022 11:30:37 +0530	[thread overview]
Message-ID: <8500896f97e47a19106f792193d1b72b3468fc29.1664258174.git.gmuthukrishn@marvell.com> (raw)
In-Reply-To: <e7c9578ea6bb9d5c9fba1bb227bf0b815dd76374.1664258174.git.gmuthukrishn@marvell.com>

In asym op, while parsing test interim info, existing buffer of size
256 bytes is not sufficient, hence setting it to maximum that a test
would need.

Fixes: 58cc98801eb ("examples/fips_validation: add JSON parsing")

Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
Acked-by: Brian Dooley <brian.dooley@intel.com>
---
 examples/fips_validation/fips_validation.c | 7 ++++---
 examples/fips_validation/fips_validation.h | 7 +++++++
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c
index e755654cd0..be0634c3ac 100644
--- a/examples/fips_validation/fips_validation.c
+++ b/examples/fips_validation/fips_validation.c
@@ -484,7 +484,7 @@ fips_test_parse_one_json_group(void)
 	json_t *param;
 
 	if (info.interim_callbacks) {
-		char json_value[256];
+		char json_value[FIPS_TEST_JSON_BUF_LEN];
 		for (i = 0; info.interim_callbacks[i].key != NULL; i++) {
 			param = json_object_get(json_info.json_test_group,
 					info.interim_callbacks[i].key);
@@ -493,11 +493,12 @@ fips_test_parse_one_json_group(void)
 
 			switch (json_typeof(param)) {
 			case JSON_STRING:
-				snprintf(json_value, 256, "%s", json_string_value(param));
+				snprintf(json_value, sizeof(json_value), "%s",
+						 json_string_value(param));
 				break;
 
 			case JSON_INTEGER:
-				snprintf(json_value, 255, "%"JSON_INTEGER_FORMAT,
+				snprintf(json_value, sizeof(json_value), "%"JSON_INTEGER_FORMAT,
 						json_integer_value(param));
 				break;
 
diff --git a/examples/fips_validation/fips_validation.h b/examples/fips_validation/fips_validation.h
index 6e5f2fce75..43e5ffe4b0 100644
--- a/examples/fips_validation/fips_validation.h
+++ b/examples/fips_validation/fips_validation.h
@@ -183,6 +183,13 @@ struct xts_interim_data {
 };
 
 #ifdef USE_JANSSON
+/*
+ * Maximum length of buffer to hold any json string.
+ * Esp, in asym op, modulo bits decide char buffer size.
+ * max = (modulo / 4)
+ */
+#define FIPS_TEST_JSON_BUF_LEN (4096 / 4)
+
 struct fips_test_json_info {
 	/* Information used for reading from json */
 	json_t *json_root;
-- 
2.25.1


  parent reply	other threads:[~2022-09-27  6:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-27  6:00 [v2 1/7] examples/fips_validation: fix parsing test group info Gowrishankar Muthukrishnan
2022-09-27  6:00 ` [v2 2/7] examples/fips_validation: add interim parse writeback Gowrishankar Muthukrishnan
2022-09-27  6:00 ` [v2 3/7] examples/fips_validation: add function to calculate SHA hash size Gowrishankar Muthukrishnan
2022-09-27  6:00 ` Gowrishankar Muthukrishnan [this message]
2022-09-27  6:00 ` [v2 5/7] examples/fips_validation: add asymmetric validation Gowrishankar Muthukrishnan
2022-09-27  6:00 ` [v2 6/7] examples/fips_validation: encode digest with hash OID Gowrishankar Muthukrishnan
2022-09-27  6:00 ` [v2 7/7] examples/fips_validation: randomize message for conformance test Gowrishankar Muthukrishnan
2022-09-27  7:26 [v2 0/7] FIPS asymmetric validation Gowrishankar Muthukrishnan
2022-09-27  7:26 ` [v2 4/7] examples/fips_validation: fix buffer size to parse JSON string Gowrishankar Muthukrishnan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8500896f97e47a19106f792193d1b72b3468fc29.1664258174.git.gmuthukrishn@marvell.com \
    --to=gmuthukrishn@marvell.com \
    --cc=anoobj@marvell.com \
    --cc=brian.dooley@intel.com \
    --cc=dev@dpdk.org \
    --cc=gakhil@marvell.com \
    --cc=jerinj@marvell.com \
    --cc=roy.fan.zhang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).