summaryrefslogtreecommitdiff
path: root/lib/kstrtox.c
diff options
context:
space:
mode:
authorPetr Mladek <pmladek@suse.com>2021-06-29 09:51:58 +0200
committerPetr Mladek <pmladek@suse.com>2021-06-29 09:51:58 +0200
commitd8c032145fccfead0c3f733e7b6aaa4e81f9d326 (patch)
tree7b150b83d4341c8bc646f33a7b0cb928dab4ee8a /lib/kstrtox.c
parent80ae552917228b97ca9f7df83f74ac306d6fd68f (diff)
parentd327ea15a305024ef0085252fa3657bbb1ce25f5 (diff)
Merge branch 'for-5.14-vsprintf-scanf' into for-linus
Diffstat (limited to 'lib/kstrtox.c')
-rw-r--r--lib/kstrtox.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/kstrtox.c b/lib/kstrtox.c
index a118b0b1e9b2..0b5fe8b41173 100644
--- a/lib/kstrtox.c
+++ b/lib/kstrtox.c
@@ -39,20 +39,22 @@ const char *_parse_integer_fixup_radix(const char *s, unsigned int *base)
/*
* Convert non-negative integer string representation in explicitly given radix
- * to an integer.
+ * to an integer. A maximum of max_chars characters will be converted.
+ *
* Return number of characters consumed maybe or-ed with overflow bit.
* If overflow occurs, result integer (incorrect) is still returned.
*
* Don't you dare use this function.
*/
-unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *p)
+unsigned int _parse_integer_limit(const char *s, unsigned int base, unsigned long long *p,
+ size_t max_chars)
{
unsigned long long res;
unsigned int rv;
res = 0;
rv = 0;
- while (1) {
+ while (max_chars--) {
unsigned int c = *s;
unsigned int lc = c | 0x20; /* don't tolower() this line */
unsigned int val;
@@ -82,6 +84,11 @@ unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long
return rv;
}
+unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *p)
+{
+ return _parse_integer_limit(s, base, p, INT_MAX);
+}
+
static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)
{
unsigned long long _res;