Soft Patch Panel
 help / color / mirror / Atom feed
From: ogawa.yasufumi@lab.ntt.co.jp
To: spp@dpdk.org, ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp
Subject: [spp] [PATCH 3/5] spp_vm: add error handling for add and del cmd
Date: Tue,  9 Oct 2018 19:52:05 +0900	[thread overview]
Message-ID: <20181009105207.42636-4-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <20181009105207.42636-1-ogawa.yasufumi@lab.ntt.co.jp>

From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>

Add error handling in do_add() and do_del() to avoid segmentation fault
caused if parse_resource_uid() is falied.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/vm/main.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/vm/main.c b/src/vm/main.c
index 7aec126..55592df 100644
--- a/src/vm/main.c
+++ b/src/vm/main.c
@@ -230,8 +230,11 @@ do_del(char *res_uid)
 	int port_id = PORT_RESET;
 	char *p_type;
 	int p_id;
+	int res;
 
-	parse_resource_uid(res_uid, &p_type, &p_id);
+	res = parse_resource_uid(res_uid, &p_type, &p_id);
+	if (res < 0)
+		return -1;
 
 	if (!strcmp(p_type, "ring")) {
 		char name[RTE_ETH_NAME_MAX_LEN];
@@ -349,11 +352,13 @@ do_add(char *res_uid)
 {
 	enum port_type type = UNDEF;
 	int port_id = PORT_RESET;
-
 	char *p_type;
 	int p_id;
+	int res;
 
-	parse_resource_uid(res_uid, &p_type, &p_id);
+	res = parse_resource_uid(res_uid, &p_type, &p_id);
+	if (res < 0)
+		return -1;
 
 	if (!strcmp(p_type, "ring")) {
 		type = RING;
@@ -430,8 +435,9 @@ parse_command(char *str)
 		cmd = FORWARD;
 
 	} else if (strncmp(token_list[0], "add", 3) == 0) {
-		RTE_LOG(DEBUG, APP, "add\n");
-		do_add(token_list[1]);
+		RTE_LOG(DEBUG, APP, "Received add command\n");
+		if (do_add(token_list[1]) < 0)
+			RTE_LOG(ERR, APP, "Failed to do_add()\n");
 
 	} else if (!strcmp(token_list[0], "patch")) {
 		RTE_LOG(DEBUG, APP, "patch\n");
@@ -464,10 +470,12 @@ parse_command(char *str)
 			add_patch(in_port, out_port);
 		}
 	} else if (strncmp(str, "del", 3) == 0) {
-		RTE_LOG(DEBUG, APP, "del\n");
+		RTE_LOG(DEBUG, APP, "Received del command\n");
 
 		cmd = STOP;
-		do_del(token_list[1]);
+
+		if (do_del(token_list[1]) < 0)
+			RTE_LOG(ERR, APP, "Failed to do_del()\n");
 	}
 
 	return ret;
-- 
2.7.4

  parent reply	other threads:[~2018-10-09 10:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-09 10:52 [spp] [PATCH 0/5] Add error handling for add and del commands ogawa.yasufumi
2018-10-09 10:52 ` [spp] [PATCH 1/5] shared: add error handling for invalid res UID ogawa.yasufumi
2018-10-09 10:52 ` [spp] [PATCH 2/5] spp_nfv: add error handling for add and del cmd ogawa.yasufumi
2018-10-09 10:52 ` ogawa.yasufumi [this message]
2018-10-09 10:52 ` [spp] [PATCH 4/5] spp_nfv: refactor add_ring_pmd ogawa.yasufumi
2018-10-09 10:52 ` [spp] [PATCH 5/5] spp_vm: " ogawa.yasufumi

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=20181009105207.42636-4-ogawa.yasufumi@lab.ntt.co.jp \
    --to=ogawa.yasufumi@lab.ntt.co.jp \
    --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).