Soft Patch Panel
 help / color / mirror / Atom feed
From: Yasufumi Ogawa <yasufum.o@gmail.com>
To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com
Subject: [spp] [PATCH] spp_primary: fix buf overflow in result of patch
Date: Tue, 22 Oct 2019 17:18:56 +0900	[thread overview]
Message-ID: <20191022081856.21489-1-yasufum.o@gmail.com> (raw)

As `patch` command is added to spp_primary, it returns the result of
the command. It is contained in variable `char port_set[32]` for
containing a port formatted as "\"%s:%d\"", but the size is not enough
for the result of patch "{\"src\":\"%s:%d\",\"dst\":\"%s:%d\"}". The
name of `port_set` is not appropriate for the purpose.

This update is to fix the issue by changing `port_set` to `port_uid` and
add another one for patch with enough size 64byte as
`char patch_set[64]`.

Fixes: f511dd01fa4b ("spp_primary: add status for forwarder thread")

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/primary/main.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/primary/main.c b/src/primary/main.c
index dbae424..fbc47c3 100644
--- a/src/primary/main.c
+++ b/src/primary/main.c
@@ -910,8 +910,9 @@ parse_command(char *str)
 	int max_token = 0;
 	uint16_t dev_id;
 	char dev_name[RTE_DEV_NAME_MAX_LEN] = { 0 };
-	char result[16] = { 0 };  /* succeeded or failed. */
-	char port_set[32] = { 0 };
+	char result[16] = { 0 };  /* "succeeded" or "failed". */
+	char port_uid[20] = { 0 };  /* "\"%s:%d\"" */
+	char patch_set[64] = { 0 };  /* "{\"src\":\"%s:%d\",\"dst\":...}" */
 	char *p_type;
 	int p_id;
 
@@ -994,12 +995,12 @@ parse_command(char *str)
 		} else
 			sprintf(result, "%s", "\"succeeded\"");
 
-		sprintf(port_set, "\"%s:%d\"", p_type, p_id);
+		sprintf(port_uid, "\"%s:%d\"", p_type, p_id);
 		memset(str, '\0', MSG_SIZE);
 		sprintf(str, "{%s:%s,%s:%s,%s:%s}",
 				"\"result\"", result,
 				"\"command\"", "\"add\"",
-				"\"port\"", port_set);
+				"\"port\"", port_uid);
 
 	} else if (!strcmp(token_list[0], "del")) {
 		RTE_LOG(DEBUG, PRIMARY, "Received del command\n");
@@ -1016,12 +1017,12 @@ parse_command(char *str)
 		} else
 			sprintf(result, "%s", "\"succeeded\"");
 
-		sprintf(port_set, "\"%s:%d\"", p_type, p_id);
+		sprintf(port_uid, "\"%s:%d\"", p_type, p_id);
 		memset(str, '\0', MSG_SIZE);
 		sprintf(str, "{%s:%s,%s:%s,%s:%s}",
 				"\"result\"", result,
 				"\"command\"", "\"del\"",
-				"\"port\"", port_set);
+				"\"port\"", port_uid);
 
 	} else if (!strcmp(token_list[0], "patch")) {
 		RTE_LOG(DEBUG, PRIMARY, "patch\n");
@@ -1088,7 +1089,7 @@ parse_command(char *str)
 				sprintf(result, "%s", "\"failed\"");
 			}
 
-			sprintf(port_set,
+			sprintf(patch_set,
 				"{\"src\":\"%s:%d\",\"dst\":\"%s:%d\"}",
 				in_p_type, in_p_id, out_p_type, out_p_id);
 
@@ -1096,7 +1097,7 @@ parse_command(char *str)
 			sprintf(str, "{%s:%s,%s:%s,%s:%s}",
 					"\"result\"", result,
 					"\"command\"", "\"patch\"",
-					"\"ports\"", port_set);
+					"\"ports\"", patch_set);
 
 			ret = 0;
 		}
-- 
2.17.1


                 reply	other threads:[~2019-10-22  8:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20191022081856.21489-1-yasufum.o@gmail.com \
    --to=yasufum.o@gmail.com \
    --cc=ferruh.yigit@intel.com \
    --cc=spp@dpdk.org \
    /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).