From mboxrd@z Thu Jan 1 00:00:00 1970 From: Fernando Nasser To: Keith Seitz Cc: gdb-patches@sources.redhat.com Subject: Re: [RFA2] Follow-up decode_line_1 crash Date: Wed, 14 Mar 2001 09:48:00 -0000 Message-id: <3AAFAE14.98B1427D@redhat.com> References: X-SW-Source: 2001-03/msg00205.html I have tried it and it looks OK (on Red Hat 7.0). Let's try it. Fernando Keith Seitz wrote: > > Problem: > > $ gdb -nw -nx -q > (gdb) b "foo" > Segmentation fault (core dumped) > > decode_linespec_1 does something like: > > char *p = *argptr; (the first quote in "foo") > if (p == '"') > { > p++; > is_quote_enclosed = 1; > } > > if (is_quote_enclosed) > { > char *closing_quote = strchr (p, '"'); > if (closing_quote && closing_quote[1] == '\0') > *closing_quote = '\0'; > } > > /* so now p looks like foo with no quotes and *argptr is "foo */ > > char *copy = (char *) alloca (p - *argptr + 1); <-- alloca of 0 bytes > memcpy (copy, *argptr, p - *argptr); <-- copy -1 bytes > > Patch: > > Index: linespec.c > =================================================================== > RCS file: /cvs/cvsfiles/devo/gdb/linespec.c,v > retrieving revision 2.4 > diff -p -p -r2.4 linespec.c > *** linespec.c 2000/12/20 14:34:15 2.4 > --- linespec.c 2001/03/14 16:16:11 > *************** decode_line_1 (char **argptr, int funfir > *** 611,620 **** > > s = NULL; > p = *argptr; > ! if (p[0] == '"') > { > is_quote_enclosed = 1; > ! p++; > } > else > is_quote_enclosed = 0; > --- 611,620 ---- > > s = NULL; > p = *argptr; > ! if (**argptr == '"') > { > is_quote_enclosed = 1; > ! (*argptr)++; > } > else > is_quote_enclosed = 0; > > Tested on RH6.2. Should be generic enough to apply to all targets. I'm no > expert at this stuff, but a crash is Just Plain Bad (TM). > > Keith -- Fernando Nasser Red Hat Canada Ltd. E-Mail: fnasser@redhat.com 2323 Yonge Street, Suite #300 Toronto, Ontario M4P 2C9