All of lore.kernel.org
 help / color / mirror / Atom feed
* 2.6.23-rc2-mm2: strtol_check_range patches
@ 2007-08-13 11:29 Alexey Dobriyan
  2007-08-13 15:42 ` Satyam Sharma
  0 siblings, 1 reply; 2+ messages in thread
From: Alexey Dobriyan @ 2007-08-13 11:29 UTC (permalink / raw)
  To: akpm, satyam; +Cc: linux-kernel

Andrew please drop
	introduce-strtol_check_range-fix.patch
	introduce-strtol_check_range.patch
from -mm.

strtol_check_range() semantics is broken, because caller can't distinguish
-E from valid negative number if he wants to negative integers. Comment
mentions this, but we don't want to such horrible and not well thought
out function to lib/ .

If anything it should be strtonum() with additional trailing '\n' check.

+ * Do not use this to convert numbers that are allowed to be negative.
+ */
+long strtol_check_range(const char *cp, long min, long max, unsigned int base)
+{
+       long ret;
+       char *p = (char *) cp;
+
+       WARN_ON(min < 0);
+       WARN_ON(max < min);
+
+       ret = simple_strtol(p, &p, base);
+
+       if (*p && (*p != '\n'))
+               return -EINVAL;
+       if ((ret < min) || (ret > max))
+               return -EINVAL;
+
+       return ret;
+}


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-08-13 16:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-13 11:29 2.6.23-rc2-mm2: strtol_check_range patches Alexey Dobriyan
2007-08-13 15:42 ` Satyam Sharma

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.