Skip to contentSkip to conversation

strict_strto* is not strict enough

PATCH Pavel Machek 1 participant 1 message Nov 22, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

It decodes "\n" as 0, which is bad, because stray echo into backlight will turn your backlight off, etc...

lib/vsprintf.c +4 -0
index a013bbc..87d12a7 100644
@@ -170,6 +170,8 @@ int strict_strtoul(const char *cp, unsig
 		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;
@@ -241,6 +243,8 @@ int strict_strtoull(const char *cp, unsi
 		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;
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html