patches for DPDK stable branches
 help / color / Atom feed
From: Kevin Laatz <kevin.laatz@intel.com>
To: David Marchand <david.marchand@redhat.com>,
	Bruce Richardson <bruce.richardson@intel.com>
Cc: dev <dev@dpdk.org>, "Yigit, Ferruh" <ferruh.yigit@intel.com>,
	dpdk stable <stable@dpdk.org>
Subject: Re: [dpdk-stable] [dpdk-dev] [PATCH] net/ring: fix unchecked return value
Date: Wed, 23 Sep 2020 11:04:34 +0100
Message-ID: <4077e642-30f2-66e9-cdbf-f8e631aeb0cf@intel.com> (raw)
In-Reply-To: <CAJFAV8wTe+DbmrYGxzm0Oydu+v1jvwCm8Zhw=Ha9Evdqjt-RVQ@mail.gmail.com>

On 23/09/2020 10:43, David Marchand wrote:
> On Wed, Sep 23, 2020 at 11:39 AM Bruce Richardson
> <bruce.richardson@intel.com> 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


  reply index

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-22 17:20 [dpdk-stable] " Kevin Laatz
2020-09-23  8:06 ` [dpdk-stable] [dpdk-dev] " David Marchand
2020-09-23  9:39   ` Bruce Richardson
2020-09-23  9:43     ` David Marchand
2020-09-23 10:04       ` Kevin Laatz [this message]
2020-09-23 10:25       ` Bruce Richardson
2020-09-25 12:43 ` [dpdk-stable] " Ferruh Yigit
2020-10-01 14:14   ` Kevin Laatz
2020-10-01 14:51     ` Ferruh Yigit
2020-10-01 17:09 ` [dpdk-stable] [PATCH v2] " Kevin Laatz
2020-10-12 11:57   ` Ferruh Yigit
2020-10-12 12:45     ` Bruce Richardson
2020-10-12 13:04       ` Ferruh Yigit
2020-10-12 13:11         ` Bruce Richardson
2020-10-13 13:07   ` [dpdk-stable] [PATCH v3] " Kevin Laatz
2020-10-13 17:23     ` Ferruh Yigit

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4077e642-30f2-66e9-cdbf-f8e631aeb0cf@intel.com \
    --to=kevin.laatz@intel.com \
    --cc=bruce.richardson@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

patches for DPDK stable branches

Archives are clonable:
	git clone --mirror http://inbox.dpdk.org/stable/0 stable/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 stable stable/ http://inbox.dpdk.org/stable \
		stable@dpdk.org
	public-inbox-index stable


Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.stable


AGPL code for this site: git clone https://public-inbox.org/ public-inbox