From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id A07E86829 for ; Fri, 27 Jun 2014 13:04:51 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 27 Jun 2014 03:59:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,559,1400050800"; d="scan'208";a="564429017" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga002.jf.intel.com with ESMTP; 27 Jun 2014 04:04:58 -0700 Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com [10.237.217.46]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id s5RB4vJJ009698; Fri, 27 Jun 2014 12:04:57 +0100 Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1]) by sivswdev02.ir.intel.com with ESMTP id s5RB4vP6018881; Fri, 27 Jun 2014 12:04:57 +0100 Received: (from pdelarax@localhost) by sivswdev02.ir.intel.com with id s5RB4vWu018877; Fri, 27 Jun 2014 12:04:57 +0100 From: Pablo de Lara To: dev@dpdk.org Date: Fri, 27 Jun 2014 12:04:57 +0100 Message-Id: <1403867097-18848-1-git-send-email-pablox.de.lara.guarch@intel.com> X-Mailer: git-send-email 1.7.0.7 Subject: [dpdk-dev] [PATCH] string: fix potential seg fault on snprintf 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: , X-List-Received-Date: Fri, 27 Jun 2014 11:04:53 -0000 From: Pablo de Lara Several functions did not check if destination buffer, used in snprintf was a non-NULL pointer. Signed-off-by: Pablo de Lara --- examples/cmdline/parse_obj_list.c | 3 +++ lib/librte_cmdline/cmdline_parse_etheraddr.c | 3 +++ lib/librte_cmdline/cmdline_parse_num.c | 2 +- lib/librte_cmdline/cmdline_parse_portlist.c | 4 ++++ lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 3 +++ 5 files changed, 14 insertions(+), 1 deletions(-) diff --git a/examples/cmdline/parse_obj_list.c b/examples/cmdline/parse_obj_list.c index 2625ca3..97dfa09 100644 --- a/examples/cmdline/parse_obj_list.c +++ b/examples/cmdline/parse_obj_list.c @@ -157,6 +157,9 @@ int complete_get_elt_obj_list(cmdline_parse_token_hdr_t *tk, int get_help_obj_list(__attribute__((unused)) cmdline_parse_token_hdr_t *tk, char *dstbuf, unsigned int size) { + if (!dstbuf) + return -1; + snprintf(dstbuf, size, "Obj-List"); return 0; } diff --git a/lib/librte_cmdline/cmdline_parse_etheraddr.c b/lib/librte_cmdline/cmdline_parse_etheraddr.c index 5285c40..774b167 100644 --- a/lib/librte_cmdline/cmdline_parse_etheraddr.c +++ b/lib/librte_cmdline/cmdline_parse_etheraddr.c @@ -170,6 +170,9 @@ cmdline_get_help_etheraddr(__attribute__((unused)) cmdline_parse_token_hdr_t *tk { int ret; + if (!dstbuf) + return -1; + ret = snprintf(dstbuf, size, "Ethernet address"); if (ret < 0) return -1; diff --git a/lib/librte_cmdline/cmdline_parse_num.c b/lib/librte_cmdline/cmdline_parse_num.c index 0b9e4d0..26ba5ef 100644 --- a/lib/librte_cmdline/cmdline_parse_num.c +++ b/lib/librte_cmdline/cmdline_parse_num.c @@ -349,7 +349,7 @@ cmdline_get_help_num(cmdline_parse_token_hdr_t *tk, char *dstbuf, unsigned int s struct cmdline_token_num_data nd; int ret; - if (!tk) + if (!tk || !dstbuf) return -1; memcpy(&nd, &((struct cmdline_token_num *)tk)->num_data, sizeof(nd)); diff --git a/lib/librte_cmdline/cmdline_parse_portlist.c b/lib/librte_cmdline/cmdline_parse_portlist.c index 7eac05c..8e3521a 100644 --- a/lib/librte_cmdline/cmdline_parse_portlist.c +++ b/lib/librte_cmdline/cmdline_parse_portlist.c @@ -163,6 +163,10 @@ cmdline_get_help_portlist(__attribute__((unused)) cmdline_parse_token_hdr_t *tk, char *dstbuf, unsigned int size) { int ret; + + if (!dstbuf) + return -1; + ret = snprintf(dstbuf, size, "range of ports as 3,4-6,8-19,20"); if (ret < 0) return -1; diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c index 7e62266..ec0ba42 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c @@ -211,6 +211,9 @@ pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf, DIR *dir; char dirname[PATH_MAX]; + if (!dstbuf) + return -1; + /* depending on kernel version, uio can be located in uio/uioX * or uio:uioX */ -- 1.7.0.7