Skip to content

Commit

Permalink
strict_strto* is not strict enough
Browse files Browse the repository at this point in the history
It decodes "\n" as 0, which is bad, because stray echo into backlight
will turn your backlight off, etc...

Signed-off-by: Pavel Machek <pavel@suse.cz>
Cc: Yi Yang <yi.y.yang@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Pavel Machek authored and Linus Torvalds committed Jan 6, 2009
1 parent ff083c8 commit e899aa8
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/vsprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ int strict_strtoul(const char *cp, unsigned int base, unsigned long *res)
return -EINVAL;

val = simple_strtoul(cp, &tail, base);
if (tail == cp)
return -EINVAL;
if ((*tail == '\0') ||
((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) {
*res = val;
Expand Down Expand Up @@ -241,6 +243,8 @@ int strict_strtoull(const char *cp, unsigned int base, unsigned long long *res)
return -EINVAL;

val = simple_strtoull(cp, &tail, base);
if (tail == cp)
return -EINVAL;
if ((*tail == '\0') ||
((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) {
*res = val;
Expand Down

0 comments on commit e899aa8

Please sign in to comment.