Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Denis PILAT <denis.pilat@st.com>
To: gdb-patches@sources.redhat.com
Subject: [PATCH] Segmentation fault when using the completion for interpreter
Date: Wed, 12 Jul 2006 14:15:00 -0000	[thread overview]
Message-ID: <44B500EA.1020506@st.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 482 bytes --]

I found a bug in gdb: when using the completion after the cli command
"interpreter-exec", an out-of-bound access occures.

Attached is a patch proposal that fixes it.

There were 2 problems in the original code in file interps.c, function 
interpreter_completer:
- the case of (num_matches == alloced) was not handled. In that case the 
matches list it not terminated by NULL.
- the xrealloc done at the end is useless since the num_matches is 
always <= alloced.

-- 
Denis PILAT


[-- Attachment #2: ChangeLog --]
[-- Type: text/plain, Size: 169 bytes --]

2006-07-12  Denis PILAT  <denis.pilat@st.com>

	* interps.c (interpreter_completer): Allocate one more item to the
	'matches' list and set them all to 0 with a xcalloc.

[-- Attachment #3: interps.c.patch --]
[-- Type: text/plain, Size: 1046 bytes --]

Index: interps.c
===================================================================
--- interps.c	(revision 486)
+++ interps.c	(working copy)
@@ -424,10 +424,11 @@ interpreter_completer (char *text, char 
   struct interp *interp;
 
   /* We expect only a very limited number of interpreters, so just
-     allocate room for all of them. */
+     allocate room for all of them plus one for the last that must be NULL
+     to correctly end the list. */
   for (interp = interp_list; interp != NULL; interp = interp->next)
     ++alloced;
-  matches = (char **) xmalloc (alloced * sizeof (char *));
+  matches = (char **) xcalloc (alloced + 1, sizeof (char *));
 
   num_matches = 0;
   textlen = strlen (text);
@@ -460,12 +461,6 @@ interpreter_completer (char *text, char 
       xfree (matches);
       matches = NULL;
     }
-  else if (num_matches < alloced)
-    {
-      matches = (char **) xrealloc ((char *) matches, ((num_matches + 1)
-						       * sizeof (char *)));
-      matches[num_matches] = NULL;
-    }
 
   return matches;
 }

             reply	other threads:[~2006-07-12 14:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-12 14:15 Denis PILAT [this message]
2006-07-12 17:14 ` Daniel Jacobowitz
2006-07-13  9:05   ` Andrew STUBBS
2006-07-16  4:12   ` Joel Brobecker
2006-07-17  8:17     ` Denis PILAT
2006-07-17 11:55     ` Andrew STUBBS

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=44B500EA.1020506@st.com \
    --to=denis.pilat@st.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