public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Ulrich Weigand" <uweigand@de.ibm.com>
To: gdb-patches@sourceware.org
Subject: [commit] Fix GDB crash due to endless recursion in namespace lookup
Date: Fri, 25 Jun 2010 16:20:00 -0000	[thread overview]
Message-ID: <201006251619.o5PGJmJQ005295@d12av02.megacenter.de.ibm.com> (raw)
In-Reply-To: <201006241809.o5OI9rPx014499@d12av02.megacenter.de.ibm.com> from "Ulrich Weigand" at Jun 24, 2010 08:09:53 PM

I wrote:

> since one of this year's C++ namespace search related changes,
> GDB will go into an endless recursion and crash due to stack
> overflow when looking up symbols in the presence of a cycle
> in the "using" directive graph.

Found it.  There is a mechanism to prevent infinite recursion, the
"searched" flag in struct using_directive, which is used in 
cp-namespace.c:cp_lookup_symbol_imports.  However, for some reason,
a similar recursive loop in cp-support.c:make_symbol_overload_list_using
did not use this flag, causing the problem.

Fixed in the obvious way by the patch below.
Tested on s390x-ibm-linux, committed to mainline.

Bye,
Ulrich


ChangeLog:

	* cp-support.c (reset_directive_searched): New function.
	(make_symbol_overload_list_using): Prevent recursive calls.


Index: gdb/cp-support.c
===================================================================
RCS file: /cvs/src/src/gdb/cp-support.c,v
retrieving revision 1.43
diff -u -p -r1.43 cp-support.c
--- gdb/cp-support.c	7 Jun 2010 17:51:03 -0000	1.43
+++ gdb/cp-support.c	25 Jun 2010 15:11:43 -0000
@@ -838,6 +838,15 @@ make_symbol_overload_list_adl (struct ty
   return sym_return_val;
 }
 
+/* Used for cleanups to reset the "searched" flag in case of an error.  */
+
+static void
+reset_directive_searched (void *data)
+{
+  struct using_direct *direct = data;
+  direct->searched = 0;
+}
+
 /* This applies the using directives to add namespaces to search in,
    and then searches for overloads in all of those namespaces.  It
    adds the symbols found to sym_return_val.  Arguments are as in
@@ -847,7 +856,7 @@ static void
 make_symbol_overload_list_using (const char *func_name,
 				 const char *namespace)
 {
-  const struct using_direct *current;
+  struct using_direct *current;
   const struct block *block;
 
   /* First, go through the using directives.  If any of them apply,
@@ -861,12 +870,27 @@ make_symbol_overload_list_using (const c
 	current != NULL;
 	current = current->next)
       {
+	/* Prevent recursive calls.  */
+	if (current->searched)
+	  continue;
+
         /* If this is a namespace alias or imported declaration ignore it.  */
         if (current->alias != NULL || current->declaration != NULL)
           continue;
 
         if (strcmp (namespace, current->import_dest) == 0)
-          make_symbol_overload_list_using (func_name, current->import_src);
+	  {
+	    /* Mark this import as searched so that the recursive call does
+	       not search it again.  */
+	    struct cleanup *old_chain;
+	    current->searched = 1;
+	    old_chain = make_cleanup (reset_directive_searched, current);
+
+	    make_symbol_overload_list_using (func_name, current->import_src);
+
+	    current->searched = 0;
+	    discard_cleanups (old_chain);
+	  }
       }
 
   /* Now, add names for this namespace.  */

-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com

      parent reply	other threads:[~2010-06-25 16:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-24 18:10 Ulrich Weigand
2010-06-25 15:46 ` sami wagiaalla
2010-06-25 16:24   ` Ulrich Weigand
2010-06-25 16:56     ` Sami Wagiaalla
2010-06-25 16:20 ` Ulrich Weigand [this message]

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=201006251619.o5PGJmJQ005295@d12av02.megacenter.de.ibm.com \
    --to=uweigand@de.ibm.com \
    --cc=gdb-patches@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).