lkml.org 
[lkml]   [2011]   [Feb]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] core: dev: don't call BUG() on bad input
Hi Nicolas,

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 :)

> "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?


--
Vasiliy Kulikov
http://www.openwall.com - bringing security into open computing environments
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2011-02-14 13:25    [W:0.041 / U:0.352 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site