Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Keith Seitz <keiths@cygnus.com>
To: gdb-patches@sources.redhat.com
Subject: [RFA2] Follow-up decode_line_1 crash
Date: Wed, 14 Mar 2001 08:28:00 -0000	[thread overview]
Message-ID: <Pine.SOL.3.91.1010314081443.2126G-100000@ryobi.cygnus.com> (raw)

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


             reply	other threads:[~2001-03-14  8:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-14  8:28 Keith Seitz [this message]
2001-03-14  9:48 ` Fernando Nasser
2001-03-14 10:29   ` Keith Seitz
2001-03-14 10:31     ` Fernando Nasser
2001-03-14 10:40   ` Keith Seitz
2001-03-14 12:32 ` Martin M. Hunt
2001-03-15  7:11   ` Fernando Nasser
2001-03-15  8:39     ` Eli Zaretskii
2001-03-15 10:06     ` Martin M. Hunt
2001-03-15  0:52 ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.SOL.3.91.1010314081443.2126G-100000@ryobi.cygnus.com \
    --to=keiths@cygnus.com \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox