From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5AF8FA04B1; Wed, 23 Sep 2020 11:39:37 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 184BE1D56B; Wed, 23 Sep 2020 11:39:36 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 73C781D380; Wed, 23 Sep 2020 11:39:34 +0200 (CEST) IronPort-SDR: qr7Tw07Qx8akAcqNnjN27aApQhoWza2I4oRg2UCb80L+yWIsUz4t/JiTCfBbjCH6yqqwiHpDGB ZlpQ7KC0nRZA== X-IronPort-AV: E=McAfee;i="6000,8403,9752"; a="140309883" X-IronPort-AV: E=Sophos;i="5.77,293,1596524400"; d="scan'208";a="140309883" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Sep 2020 02:39:33 -0700 IronPort-SDR: K3uE70rVR4VqtW+7Mqo21R0kJJXHfGKsvFkBsnLdW3v0TAw+qS4Gbr4n5ZGVY3cI4pCqCLO1pY H4gv+oJO8Qqw== X-IronPort-AV: E=Sophos;i="5.77,293,1596524400"; d="scan'208";a="305310563" Received: from bricha3-mobl.ger.corp.intel.com ([10.213.7.171]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-SHA; 23 Sep 2020 02:39:31 -0700 Date: Wed, 23 Sep 2020 10:39:27 +0100 From: Bruce Richardson To: David Marchand Cc: Kevin Laatz , dev , "Yigit, Ferruh" , dpdk stable Message-ID: <20200923093927.GA1757@bricha3-MOBL.ger.corp.intel.com> References: <20200922172015.266698-1-kevin.laatz@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: Re: [dpdk-dev] [PATCH] net/ring: fix unchecked return value X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Wed, Sep 23, 2020 at 10:06:25AM +0200, David Marchand wrote: > On Tue, Sep 22, 2020 at 7:25 PM Kevin Laatz wrote: > > > > Add a check for the return value of the sscanf call in > > parse_internal_args(), returning an error if we don't get the expected > > result. > > > > Coverity issue: 362049 > > Fixes: 96cb19521147 ("net/ring: use EAL APIs in PMD specific API") > > Cc: stable@dpdk.org > > > > Signed-off-by: Kevin Laatz > > --- > > drivers/net/ring/rte_eth_ring.c | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/net/ring/rte_eth_ring.c b/drivers/net/ring/rte_eth_ring.c > > index 40fe1ca4ba..62060e46ce 100644 > > --- a/drivers/net/ring/rte_eth_ring.c > > +++ b/drivers/net/ring/rte_eth_ring.c > > @@ -539,7 +539,8 @@ parse_internal_args(const char *key __rte_unused, const char *value, > > struct ring_internal_args **internal_args = data; > > void *args; > > > > - sscanf(value, "%p", &args); > > + if (sscanf(value, "%p", &args) != 1) > > + return -1; > > Not sure this really needs fixing, as I understood the internal option > is something only the driver uses. > > On the patch itself, sscanf stops at the first character it deems > incorrect, meaning that you would not detect trailing chars, like for > 0x1234Z. > You can detect this by adding a canary. > > $ cat sscanf.c > #include > > int main(int argc, char *argv[]) > { > void *args; > char c; > > if (sscanf(argv[1], "%p", &args) != 1) > printf("'%%p' KO for %s\n", argv[1]); > else > printf("'%%p' ok for %s\n", argv[1]); > > if (sscanf(argv[1], "%p%c", &args, &c) != 1) > printf("'%%p%%c' KO for %s\n", argv[1]); > else > printf("'%%p%%c' ok for %s\n", argv[1]); > return 0; > } > > $ gcc -o sscanf -Wall -Werror sscanf.c > > $ ./sscanf 0x1234 > '%p' ok for 0x1234 > '%p%c' ok for 0x1234 > > $ ./sscanf 0x1234Z > '%p' ok for 0x1234Z > '%p%c' KO for 0x1234Z > I think a more standard way of checking for trailing chars is to use %n which stores the number of chars processed. Then check that against strlen. For example something like: if (sscanf(value, "%p%n", args, n) != 1 || n != strlen(value)) { /* do error handling */ }