lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20150409130247.18f3133c58b5ebc11f0f64d8@linux-foundation.org>
Date:	Thu, 9 Apr 2015 13:02:47 -0700
From:	Andrew Morton <akpm@...ux-foundation.org>
To:	Alexey Dobriyan <adobriyan@...il.com>
Cc:	linux-kernel@...r.kernel.org
Subject: Re: [PATCH] Add parse_integer() (replacement for simple_strto*())

On Thu, 9 Apr 2015 18:26:14 +0300 Alexey Dobriyan <adobriyan@...il.com> wrote:

> kstrto*() and kstrto*_from_user() family of functions were added
> help with parsing one integer written as string to proc/sysfs/debugfs
> files and pass it elsewhere. But they have a limitation: string passed
> must end with \0 or \n\0. There are enough places where kstrto*()
> functions can't be used because of this limitation. Trivial example:
> parse "%u.%u".
> 
> ...
>
>  include/linux/kernel.h |   72 +++++++++++++++++++
>  lib/Makefile           |    1 
>  lib/kstrtox.c          |   27 +------
>  lib/parse-integer.c    |  180 +++++++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 257 insertions(+), 23 deletions(-)

That's a lot of code for something which is almost the same as
kstrtofoo().

Can we hack up _kstrtoull() to optionally provide the new behaviour?
We could use the top bit of `base' to select the behaviour.  Something
like

--- a/lib/kstrtox.c~a
+++ a/lib/kstrtox.c
@@ -87,19 +87,23 @@ static int _kstrtoull(const char *s, uns
 {
 	unsigned long long _res;
 	unsigned int rv;
+	const char *cursor;
+	const unsigned int __base = base & 0x7fffffff;
 
-	s = _parse_integer_fixup_radix(s, &base);
-	rv = _parse_integer(s, base, &_res);
+	cursor = _parse_integer_fixup_radix(s, &__base);
+	rv = _parse_integer(cursor, __base, &_res);
 	if (rv & KSTRTOX_OVERFLOW)
 		return -ERANGE;
 	if (rv == 0)
 		return -EINVAL;
-	s += rv;
-	if (*s == '\n')
-		s++;
-	if (*s)
-		return -EINVAL;
+	cursor += rv;
 	*res = _res;
+	if (base & 0x80000000)
+		return cursor - s;
+	if (*cursor == '\n')
+		cursor++;
+	if (*cursor)
+		return -EINVAL;
 	return 0;
 }
 
then add a bunch of wrappers?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ