From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21612 invoked by alias); 25 Jun 2010 16:20:01 -0000 Received: (qmail 21599 invoked by uid 22791); 25 Jun 2010 16:19:58 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,MSGID_FROM_MTA_HEADER,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mtagate4.de.ibm.com (HELO mtagate4.de.ibm.com) (195.212.17.164) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 25 Jun 2010 16:19:52 +0000 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate4.de.ibm.com (8.13.1/8.13.1) with ESMTP id o5PGJnVA023638 for ; Fri, 25 Jun 2010 16:19:49 GMT Received: from d12av02.megacenter.de.ibm.com (d12av02.megacenter.de.ibm.com [9.149.165.228]) by d12nrmr1607.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o5PGJnrP1618062 for ; Fri, 25 Jun 2010 18:19:49 +0200 Received: from d12av02.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id o5PGJnWt005333 for ; Fri, 25 Jun 2010 18:19:49 +0200 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.12.11) with SMTP id o5PGJmJQ005295 for ; Fri, 25 Jun 2010 18:19:48 +0200 Message-Id: <201006251619.o5PGJmJQ005295@d12av02.megacenter.de.ibm.com> Received: by tuxmaker.boeblingen.de.ibm.com (sSMTP sendmail emulation); Fri, 25 Jun 2010 18:19:48 +0200 Subject: [commit] Fix GDB crash due to endless recursion in namespace lookup To: gdb-patches@sourceware.org Date: Fri, 25 Jun 2010 16:20:00 -0000 From: "Ulrich Weigand" In-Reply-To: <201006241809.o5OI9rPx014499@d12av02.megacenter.de.ibm.com> from "Ulrich Weigand" at Jun 24, 2010 08:09:53 PM MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-06/txt/msg00581.txt.bz2 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