All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nicolas de Pesloüan" <nicolas.2p.debian@gmail.com>
To: Vasiliy Kulikov <segoon@openwall.com>
Cc: linux-kernel@vger.kernel.org,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <eric.dumazet@gmail.com>,
	Tom Herbert <therbert@google.com>,
	Changli Gao <xiaosuo@gmail.com>, Jesse Gross <jesse@nicira.com>,
	netdev@vger.kernel.org
Subject: Re: [PATCH] core: dev: don't call BUG() on bad input
Date: Mon, 14 Feb 2011 14:01:44 +0100	[thread overview]
Message-ID: <4D5927B8.2070704@gmail.com> (raw)
In-Reply-To: <20110214122313.GA10062@albatros>

Le 14/02/2011 13:23, Vasiliy Kulikov a écrit :
> Hi Nicolas,

Hi Vasiliy,

> On Mon, Feb 14, 2011 at 13:16 +0100, Nicolas de Pesloüan wrote:
>>> -	BUG_ON(strlen(name)>= sizeof(dev->name));
>>> +	if (strnlen(name, sizeof(dev->name))>= sizeof(dev->name)) {
>
> Ehh...  Space after ")" is needed :)

:-D

>> "size_t strnlen(const char *s, size_t maxlen) : The strnlen()
>> function returns strlen(s), if that is less than maxlen, or maxlen
>> if there is no '\0' character among the first maxlen characters
>> pointed to by s."
>>
>> How can strnlen(name, sizeof(dev->name)) be greater than sizeof(dev->name)?
>>
>> Shouldn't it be "if (strnlen(name, sizeof(dev->name)) == sizeof(dev->name))" instead?
>
> Not a big deal, but MO it's better to guard from everything that
> is not a good input by negating the check.  strnlen()<  sizeof() is OK,
> strnlen()>= sizeof() is bad.  Is "==" more preferable for net/ coding style?

Agreed, both cannot cause any troubles. == is supposed to be better from the API point of view, but 
 >= is probably more readable.

	Nicolas.

  reply	other threads:[~2011-02-14 13:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-14 10:56 [PATCH] core: dev: don't call BUG() on bad input Vasiliy Kulikov
2011-02-14 12:16 ` Nicolas de Pesloüan
2011-02-14 12:23   ` Vasiliy Kulikov
2011-02-14 13:01     ` Nicolas de Pesloüan [this message]
2011-02-15 23:02 ` Stephen Hemminger

Reply instructions:

You may reply publicly 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=4D5927B8.2070704@gmail.com \
    --to=nicolas.2p.debian@gmail.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=jesse@nicira.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=segoon@openwall.com \
    --cc=therbert@google.com \
    --cc=xiaosuo@gmail.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.