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>] [day] [month] [year] [list]
Date:	Mon, 05 Nov 2012 08:26:43 +0000
From:	"Jan Beulich" <JBeulich@...e.com>
To:	"Namit Gupta" <namit2010@...il.com>
Cc:	"George Spelvin" <linux@...izon.com>,
	"Andrei Emeltchenko" <andrei.emeltchenko@...el.com>,
	"Andrew Morton" <akpm@...ux-foundation.org>,
	"Andy Shevchenko" <andriy.shevchenko@...ux.intel.com>,
	"open list" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] Lib:The patch include fix for "-" during string to
 long conversion

>>> On 04.11.12 at 14:26, Namit Gupta <namit2010@...il.com> wrote:
> API simple_strtol() and simple_strtoul() are giving incorrect result for
> string "-".
> These API's consider "-" as a '-' (negative integer) and return incorrect
> string pointer.
> The API returns pointer next to '-' character. However it should return
> starting pointer of the string.

Where is that behavior specified? If we take the C standard as
reference, it is not being made explicit whether, for "base" other
than zero, the sequence of letters and digits has to be non-empty.

If we take this as implied, then your patch should not only handle
"-" alone, but also cases where "-" is followed by other than a
letter or digit, or an out of range one.

Jan

> Below I have included possible solution for that issue.
> Please review.
> 
> 
> From eea8b5fd7e5bb7b206a41f5eec934152a77a9431 Mon Sep 17 00:00:00 2001
> From: Namit Gupta <namit2010@...il.com>
> Date: Sun, 4 Nov 2012 23:36:23 +0530
> Subject: [PATCH 1/1] Lib:The patch include fix for "-" during string to
> long conversion
> 
> API simple_strtol and simple_strtoll give wrong result for string "-",
> The API consider "-" as a -ve number which and give incorrect result
> for "-" string.
> 
> Signed-off-by: Namit Gupta <namit2010@...il.com>
> ---
>  lib/vsprintf.c |   20 ++++++++++++++++----
>  1 files changed, 16 insertions(+), 4 deletions(-)
> 
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index 39c99fe..cde449d 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -76,8 +76,14 @@ EXPORT_SYMBOL(simple_strtoul);
>   */
>  long simple_strtol(const char *cp, char **endp, unsigned int base)
>  {
> -    if (*cp == '-')
> -        return -simple_strtoul(cp + 1, endp, base);
> +    if (*cp == '-') {
> +        if (*(cp+1))
> +            return -simple_strtoul(cp + 1, endp, base);
> +        else if (*endp) { /* The string contains only "-"*/
> +            *endp = (char *)cp;
> +            return 0;
> +        }
> +    }
> 
>      return simple_strtoul(cp, endp, base);
>  }
> @@ -91,8 +97,14 @@ EXPORT_SYMBOL(simple_strtol);
>   */
>  long long simple_strtoll(const char *cp, char **endp, unsigned int base)
>  {
> -    if (*cp == '-')
> -        return -simple_strtoull(cp + 1, endp, base);
> +    if (*cp == '-') {
> +        if (*(cp+1))
> +            return -simple_strtoull(cp + 1, endp, base);
> +        else if (*endp) { /* The string contains only "-"*/
> +            *endp = (char *)cp;
> +            return 0;
> +        }
> +    }
> 
>      return simple_strtoull(cp, endp, base);
>  }
> -- 
> 1.7.1
> 
> 
> Regards,
> Namit



--
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