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 Tue, 24 Apr 2012 22:15:50 -0700, Paul wrote:
> On Tue, Apr 24, 2012 at 10:05 PM, Siddhesh Poyarekar
> <siddhesh@redhat.com> wrote:
> > ping?
> >
> > On Fri, 20 Apr 2012 12:07:24 +0530, Siddhesh wrote:
> ...
> >> Right, thanks for catching that; not sure how I missed it. Updated
> >> patch attached, also with Copyright years updated.
>
> I see the copyright update, but not '0xABCDEF' update.
>
> Did you attach the right patch?
>
> Thanks,
Ugh, no I did not. Here's the right patch.
--
Siddhesh
diff --git a/elf/dl-minimal.c b/elf/dl-minimal.c
index 316de99..94e93df 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,26 @@ __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)
+ {
+ if (*nptr >= 'a' && *nptr <= 'f')
+ digval = *nptr - 'a' + 10;
+ else if (*nptr >= 'A' && *nptr <= 'F')
+ digval = *nptr - 'A' + 10;
+ else
+ break;
+ }
+ else
+ break;
+
+ if (result > ULONG_MAX / base
+ || (result == ULONG_MAX / base && digval > ULONG_MAX % base))
{
errno = ERANGE;
if (endptr != NULL)
--
1.7.7.6