This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Don't call strchr with the NULL character.
- From: "Andrew Burgess" <aburgess at broadcom dot com>
- To: gdb-patches at sourceware dot org
- Cc: "Andreas Schwab" <schwab at linux-m68k dot org>, Paul_Koning at Dell dot com
- Date: Fri, 12 Jul 2013 10:17:58 +0100
- Subject: Re: [PATCH] Don't call strchr with the NULL character.
- References: <51DEDA0E dot 8020809 at broadcom dot com>
On 11/07/2013 5:15 PM, Andrew Burgess wrote:
> In the printf code we call strchr without guarding against the
> case where the second parameter is NULL.
>
> My local manpage for strchr doesn't say what happens in this case,
> but this file: src/libiberty/strchr.c
> suggests the results are undefined, and indeed, the answer I see is
> not NULL (which is what I might have hoped for).
Thanks to both Andreas and Paul for pointing out more up to
date manual pages that explain the behaviour is NOT undefined
at all.
That said, my patch (I believe) fixes gdb given the /current/
behaviour, which I thought was undefined, but is in fact well
defined. Either way I believe this patch is required.
Here's an example from before my patch:
while (strchr ("0-+ #", *f))
{
if (*f == '#')
seen_hash = 1;
else if (*f == '0')
seen_zero = 1;
else if (*f == ' ')
seen_space = 1;
else if (*f == '+')
seen_plus = 1;
f++;
}
If *f is the end of string NULL character then the loop
above will run off the end of the string.
Thanks,
Andrew