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 81ED5A04B1 for ; Wed, 23 Sep 2020 12:04:43 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 457361D969; Wed, 23 Sep 2020 12:04:43 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id 5311D1D969; Wed, 23 Sep 2020 12:04:41 +0200 (CEST) IronPort-SDR: v15LrRbyDm4YSfOBHHWtXoQhjiw2218UtIzUKeaWgAoVOCXXTZUr5B5DP/OP5VGTpu0ENhM686 7IBEF3JuTmOw== X-IronPort-AV: E=McAfee;i="6000,8403,9752"; a="148584049" X-IronPort-AV: E=Sophos;i="5.77,293,1596524400"; d="scan'208";a="148584049" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Sep 2020 03:04:40 -0700 IronPort-SDR: Tes2aDUF8aZDp0gxf2ABYtmhZS0xbg/Dcv2HhtKgL1yRyeDBtoY097LWgbknca06O3wchN2Jaw OGlJl+2gSr6w== X-IronPort-AV: E=Sophos;i="5.77,293,1596524400"; d="scan'208";a="486379872" Received: from jpkijak-mobl.ger.corp.intel.com (HELO [10.213.192.85]) ([10.213.192.85]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Sep 2020 03:04:37 -0700 To: David Marchand , Bruce Richardson Cc: dev , "Yigit, Ferruh" , dpdk stable References: <20200922172015.266698-1-kevin.laatz@intel.com> <20200923093927.GA1757@bricha3-MOBL.ger.corp.intel.com> From: Kevin Laatz Message-ID: <4077e642-30f2-66e9-cdbf-f8e631aeb0cf@intel.com> Date: Wed, 23 Sep 2020 11:04:34 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-GB Subject: Re: [dpdk-stable] [dpdk-dev] [PATCH] net/ring: fix unchecked return value X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" On 23/09/2020 10:43, David Marchand wrote: > On Wed, Sep 23, 2020 at 11:39 AM Bruce Richardson > wrote: >> 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 */ >> } >> > The man is a bit scary about %n: > > The C standard says: "Execution of a %n directive does not increment > the assignment count returned at the completion of execution" but the > Corrigendum seems to contradict this. Probably it is wise not to make > any assumptions on the effect of %n conversions on the return value. I still think the check is required. As you rightly point out, the value will be truncated once sscanf deems a character incorrect. This will happen regardless of if we check the return or not. What the check catches, however, is the case where the incorrect character comes at the beginning, e.g. Z0x1234 - which would truncated the entire arg. $ ./sscanf Z0x1234 '%p' KO for Z0x1234 '%p%c' KO for Z0x1234 --- Kevin