From patchwork Mon Nov 7 14:22:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fan Zhang X-Patchwork-Id: 16968 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 94E175587; Mon, 7 Nov 2016 15:22:06 +0100 (CET) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id 479B55583 for ; Mon, 7 Nov 2016 15:22:05 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP; 07 Nov 2016 06:22:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.31,606,1473145200"; d="scan'208"; a="1081734295" Received: from sie-lab-212-071.ir.intel.com (HELO silpixa00381633.ir.intel.com) ([10.237.212.71]) by fmsmga002.fm.intel.com with ESMTP; 07 Nov 2016 06:22:03 -0800 From: Fan Zhang To: dev@dpdk.org Cc: sergio.gonzalez.monroy@intel.com Date: Mon, 7 Nov 2016 14:22:02 +0000 Message-Id: <1478528522-211060-1-git-send-email-roy.fan.zhang@intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1478175163-229116-4-git-send-email-roy.fan.zhang@intel.com> References: <1478175163-229116-4-git-send-email-roy.fan.zhang@intel.com> Subject: [dpdk-dev] [PATCH v2] examples/ipsec-secgw: fix pointer to local outside scope X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Coverity issue: 137871 Fixes: 0d547ed03717 ("examples/ipsec-secgw: support configuration file") Signed-off-by: Fan Zhang --- examples/ipsec-secgw/parser.c | 120 ++++++++++++++++++++---------------------- 1 file changed, 58 insertions(+), 62 deletions(-) diff --git a/examples/ipsec-secgw/parser.c b/examples/ipsec-secgw/parser.c index ede08d8..f1afdb7 100644 --- a/examples/ipsec-secgw/parser.c +++ b/examples/ipsec-secgw/parser.c @@ -503,86 +503,82 @@ parse_cfg_file(const char *cfg_filename) do { char oneline[1024]; - + char *pos; get_s = fgets(oneline, 1024, f); - if (get_s) { - char *pos; - line_num++; + if (!get_s) + break; - if (strlen(oneline) > 1022) { - rte_panic("%s:%u: error: the line " - "contains more characters the " - "parser can handle\n", - cfg_filename, line_num); - goto error_exit; - } + line_num++; - /* process comment char '#' */ - if (oneline[0] == '#') - continue; + if (strlen(oneline) > 1022) { + rte_panic("%s:%u: error: the line " + "contains more characters the " + "parser can handle\n", + cfg_filename, line_num); + goto error_exit; + } - pos = strchr(oneline, '#'); - if (pos != NULL) - *pos = '\0'; - - /* process line concatenator '\' */ - pos = strchr(oneline, 92); - if (pos != NULL) { - if (pos != oneline+strlen(oneline) - 2) { - rte_panic("%s:%u: error: no " - "character should exist " - "after '\\' symbol\n", - cfg_filename, line_num); - goto error_exit; - } - - *pos = '\0'; - - if (strlen(oneline) + strlen(str) > 1022) { - rte_panic("%s:%u: error: the " - "concatenated line " - "contains more characters " - "the parser can handle\n", - cfg_filename, line_num); - goto error_exit; - } - - strncpy(str + strlen(str), oneline, - strlen(oneline)); + /* process comment char '#' */ + if (oneline[0] == '#') + continue; - continue; + pos = strchr(oneline, '#'); + if (pos != NULL) + *pos = '\0'; + + /* process line concatenator '\' */ + pos = strchr(oneline, 92); + if (pos != NULL) { + if (pos != oneline+strlen(oneline) - 2) { + rte_panic("%s:%u: error: no character " + "should exist after '\\'\n", + cfg_filename, line_num); + goto error_exit; } - /* copy the line to str and process */ + *pos = '\0'; + if (strlen(oneline) + strlen(str) > 1022) { - rte_panic("%s:%u: error: the line " - "contains more characters the " - "parser can handle\n", + rte_panic("%s:%u: error: the " + "concatenated line contains more " + "characters the parser can " + "handle\n", cfg_filename, line_num); goto error_exit; } + strncpy(str + strlen(str), oneline, strlen(oneline)); - str[strlen(str)] = '\n'; - if (cmdline_parse(cl, str) < 0) { - rte_panic("%s:%u: error: parsing \"%s\" " - "failed\n", cfg_filename, - line_num, str); - goto error_exit; - } + continue; + } - if (status.status < 0) { - rte_panic("%s:%u: error: %s", - cfg_filename, line_num, - status.parse_msg); - goto error_exit; - } + /* copy the line to str and process */ + if (strlen(oneline) + strlen(str) > 1022) { + rte_panic("%s:%u: error: the line contains more " + "characters the parser can handle\n", + cfg_filename, line_num); + goto error_exit; + } + strncpy(str + strlen(str), oneline, + strlen(oneline)); + + str[strlen(str)] = '\n'; + if (cmdline_parse(cl, str) < 0) { + rte_panic("%s:%u: error: parsing \"%s\" failed\n", + cfg_filename, line_num, str); + goto error_exit; + } - memset(str, 0, 1024); + if (status.status < 0) { + rte_panic("%s:%u: error: %s", cfg_filename, + line_num, status.parse_msg); + goto error_exit; } - } while (get_s != NULL); + + memset(str, 0, 1024); + } while (1); cmdline_stdin_exit(cl); fclose(f);