From: Amerigo Wang <amwang@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: akpm@linux-foundation.org, Amerigo Wang <amwang@redhat.com>
Subject: [Patch] lib: make strict_strtoul() more strict
Date: Mon, 6 Jul 2009 06:11:08 -0400 [thread overview]
Message-ID: <20090706101323.6737.62028.sendpatchset@localhost.localdomain> (raw)
Let strict_strtoul() to reject strings longer than
ULONG_MAX's string.
So does strict_stroull().
Update their documents.
(Tested on x86_64.)
Signed-off-by: WANG Cong <amwang@redhat.com>
Cc: akpm@linux-foundation.org
---
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 756ccaf..f1f7bd7 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -143,7 +143,8 @@ long long simple_strtoll(const char *cp, char **endp, unsigned int base)
* @res: The converted result value
*
* strict_strtoul converts a string to an unsigned long only if the
- * string is really an unsigned long string, any string containing
+ * string is really an unsigned long string, any string has more than the
+ * number of digits in ULONG_MAX will be rejected, any string containing
* any invalid char at the tail will be rejected and -EINVAL is returned,
* only a newline char at the tail is acceptible because people generally
* change a module parameter in the following way:
@@ -168,6 +169,8 @@ int strict_strtoul(const char *cp, unsigned int base, unsigned long *res)
len = strlen(cp);
if (len == 0)
return -EINVAL;
+ if (len > snprintf(NULL, 0, "%ld", ULONG_MAX))
+ return -EINVAL;
val = simple_strtoul(cp, &tail, base);
if (tail == cp)
@@ -216,7 +219,8 @@ EXPORT_SYMBOL(strict_strtol);
* @res: The converted result value
*
* strict_strtoull converts a string to an unsigned long long only if the
- * string is really an unsigned long long string, any string containing
+ * string is really an unsigned long long string, any string has more than
+ * the number of digits in ULLONG_MAX will be rejected, any string containing
* any invalid char at the tail will be rejected and -EINVAL is returned,
* only a newline char at the tail is acceptible because people generally
* change a module parameter in the following way:
@@ -241,6 +245,8 @@ int strict_strtoull(const char *cp, unsigned int base, unsigned long long *res)
len = strlen(cp);
if (len == 0)
return -EINVAL;
+ if (len > snprintf(NULL, 0, "%lld", ULLONG_MAX))
+ return -EINVAL;
val = simple_strtoull(cp, &tail, base);
if (tail == cp)
reply other threads:[~2009-07-06 10:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20090706101323.6737.62028.sendpatchset@localhost.localdomain \
--to=amwang@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox