From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from bcmv-tmail01.ecl.ntt.co.jp (bcmv-tmail01.ecl.ntt.co.jp [124.146.185.148]) by dpdk.org (Postfix) with ESMTP id 63BE91B466 for ; Tue, 9 Oct 2018 12:52:18 +0200 (CEST) Received: from bcmv-ns01.ecl.ntt.co.jp (bcmv-ns01.ecl.ntt.co.jp [129.60.83.123]) by bcmv-tmail01.ecl.ntt.co.jp (8.14.4/8.14.4) with ESMTP id w99AqHOR017820; Tue, 9 Oct 2018 19:52:17 +0900 Received: from bcmv-ns01.ecl.ntt.co.jp (localhost [127.0.0.1]) by bcmv-ns01.ecl.ntt.co.jp (Postfix) with ESMTP id 32C0B125; Tue, 9 Oct 2018 19:52:17 +0900 (JST) Received: from localhost.localdomain (unknown [129.60.13.51]) by bcmv-ns01.ecl.ntt.co.jp (Postfix) with ESMTP id 2611D119; Tue, 9 Oct 2018 19:52:17 +0900 (JST) From: ogawa.yasufumi@lab.ntt.co.jp To: spp@dpdk.org, ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp Date: Tue, 9 Oct 2018 19:52:04 +0900 Message-Id: <20181009105207.42636-3-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20181009105207.42636-1-ogawa.yasufumi@lab.ntt.co.jp> References: <20181009105207.42636-1-ogawa.yasufumi@lab.ntt.co.jp> X-TM-AS-MML: disable Subject: [spp] [PATCH 2/5] spp_nfv: add error handling for add and del cmd X-BeenThere: spp@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Soft Patch Panel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Oct 2018 10:52:19 -0000 From: Yasufumi Ogawa 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 --- src/nfv/nfv.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/nfv/nfv.c b/src/nfv/nfv.c index 931269d..e245a26 100644 --- a/src/nfv/nfv.c +++ b/src/nfv/nfv.c @@ -290,8 +290,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, "vhost")) { port_id = find_port_id(p_id, VHOST); @@ -647,11 +650,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, "vhost")) { type = VHOST; @@ -740,8 +745,9 @@ parse_command(char *str) cmd = FORWARD; } else if (!strcmp(token_list[0], "add")) { - 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"); @@ -775,10 +781,12 @@ parse_command(char *str) } } else if (!strcmp(token_list[0], "del")) { - 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