lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <4D5927B8.2070704@gmail.com>
Date:	Mon, 14 Feb 2011 14:01:44 +0100
From:	Nicolas de Pesloüan 
	<nicolas.2p.debian@...il.com>
To:	Vasiliy Kulikov <segoon@...nwall.com>
CC:	linux-kernel@...r.kernel.org,
	"David S. Miller" <davem@...emloft.net>,
	Eric Dumazet <eric.dumazet@...il.com>,
	Tom Herbert <therbert@...gle.com>,
	Changli Gao <xiaosuo@...il.com>,
	Jesse Gross <jesse@...ira.com>, netdev@...r.kernel.org
Subject: Re: [PATCH] core: dev: don't call BUG() on bad input

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.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ