All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexey Dobriyan <adobriyan@sw.ru>
To: akpm@osdl.org, satyam@infradead.org
Cc: linux-kernel@vger.kernel.org
Subject: 2.6.23-rc2-mm2: strtol_check_range patches
Date: Mon, 13 Aug 2007 15:29:07 +0400	[thread overview]
Message-ID: <20070813112907.GA6620@localhost.sw.ru> (raw)

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;
+}


             reply	other threads:[~2007-08-13 14:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-13 11:29 Alexey Dobriyan [this message]
2007-08-13 15:42 ` 2.6.23-rc2-mm2: strtol_check_range patches Satyam Sharma

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070813112907.GA6620@localhost.sw.ru \
    --to=adobriyan@sw.ru \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=satyam@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.