This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 1/2] Parse hex and octal strings correctly in__strtoul_internal
On Thu, 19 Apr 2012 21:18:49 -0700, Paul wrote:
> As far as I can tell, the patch handles 0xabcdef, but not 0xABCDEF.
>
> Please consider handling either case; not doing that is sure to
> surprise somebody down the line.
>
Right, thanks for catching that; not sure how I missed it. Updated
patch attached, also with Copyright years updated.
--
Siddhesh
diff --git a/elf/dl-minimal.c b/elf/dl-minimal.c
index 316de99..5f5f3d2 100644
--- a/elf/dl-minimal.c
+++ b/elf/dl-minimal.c
@@ -1,6 +1,5 @@
/* Minimal replacements for basic facilities used in the dynamic linker.
- Copyright (C) 1995-1998,2000-2002,2004-2006,2007,2009
- Free Software Foundation, Inc.
+ Copyright (C) 1995-2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -264,11 +263,19 @@ __strtoul_internal (const char *nptr, char **endptr, int base, int group)
base = 8;
}
- while (*nptr >= '0' && *nptr <= '9')
+ while (1)
{
- unsigned long int digval = *nptr - '0';
- if (result > ULONG_MAX / 10
- || (result == ULONG_MAX / 10 && digval > ULONG_MAX % 10))
+ unsigned long int digval;
+ unsigned max_digit = (base <= 10) ? base - 1 : 9;
+ if (*nptr >= '0' && *nptr <= '0' + max_digit)
+ digval = *nptr - '0';
+ else if (base == 16 && (*nptr >= 'a' && *nptr <= 'f'))
+ digval = *nptr - 'a' + 10;
+ else
+ break;
+
+ if (result > ULONG_MAX / base
+ || (result == ULONG_MAX / base && digval > ULONG_MAX % base))
{
errno = ERANGE;
if (endptr != NULL)
--
1.7.7.6