From patchwork Fri Feb 4 23:16:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Magnusson X-Patchwork-Id: 533021 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p14NGPQb010832 for ; Fri, 4 Feb 2011 23:16:26 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752665Ab1BDXQZ (ORCPT ); Fri, 4 Feb 2011 18:16:25 -0500 Received: from mail-bw0-f46.google.com ([209.85.214.46]:33258 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752582Ab1BDXQY (ORCPT ); Fri, 4 Feb 2011 18:16:24 -0500 Received: by bwz15 with SMTP id 15so3245492bwz.19 for ; Fri, 04 Feb 2011 15:16:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:date:from:to:cc:subject:message-id :mail-followup-to:mime-version:content-type:content-disposition :user-agent; bh=QicfSEkG7aLfWPPuTVkz4CPXqIEj6y6zSAi2LD7C+Go=; b=glhZDwEjG9wStLyVx0sKK/7WWhE+6Nb+Xi2thRJ2fdJVlbcHQagshquaB81dy6/tiq jyXaGtUWQD46dh/NZKRMdU2ZxRvzYQAT0GT25ZL112bsv4oES1dLzXzCOJg3w0yFFBap bhSKkNDqCa26hYZjc87j+12sVCSYrvqllfmDM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:mail-followup-to:mime-version :content-type:content-disposition:user-agent; b=dIQ2FRF9LhhURprCDEZ/Fq2907uQp76n0PQiJrmmOvke/3NbgGbtJyFaPnoSI1fhQa MB/VtZaHC5H6tGY9IZHZbEj/ojwwmm2RIXl81rhUgTArLdRLcGsLT48Uk69Yro1nfJi7 /hPRpTpulgmNpNtqOUrQwm+RFoYUDMjdVEBBg= Received: by 10.204.14.202 with SMTP id h10mr10389620bka.182.1296861382604; Fri, 04 Feb 2011 15:16:22 -0800 (PST) Received: from ulf (pat.se.opera.com [88.131.66.80]) by mx.google.com with ESMTPS id rc9sm705751bkb.2.2011.02.04.15.16.20 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 04 Feb 2011 15:16:21 -0800 (PST) Date: Sat, 5 Feb 2011 00:16:15 +0100 From: Ulf Magnusson To: linux-kbuild@vger.kernel.org Cc: zippel@linux-m68k.org, linux-kernel@vger.kernel.org Subject: [PATCH] kconfig: undefined symbols can crash dependency loop detection Message-ID: <20110204231611.GA9344@ulf> Mail-Followup-To: Ulf Magnusson , linux-kbuild@vger.kernel.org, zippel@linux-m68k.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 04 Feb 2011 23:16:26 +0000 (UTC) diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index a796c95..81a217f 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -972,6 +973,10 @@ static void sym_check_print_recursive(struct symbol *last_sym) struct menu *menu = NULL; struct property *prop; struct dep_stack cv_stack; + const char *filename; + int lineno; + char undef_msg_buf[100]; + int snprintf_size; if (sym_is_choice_value(last_sym)) { dep_stack_insert(&cv_stack, last_sym); @@ -1001,18 +1006,37 @@ static void sym_check_print_recursive(struct symbol *last_sym) break; } } + + if (prop) { + filename = prop->file->name; + lineno = prop->lineno; + } else { + /* The dependency loop involves an undefined symbol. + * Checking sym->name is probably unnecessary here, but + * just to be on the safe side. */ + snprintf_size = snprintf(undef_msg_buf, + sizeof(undef_msg_buf), + "", + sym->name ? sym->name : + ""); + if (snprintf_size > sizeof(undef_msg_buf)) + undef_msg_buf[sizeof(undef_msg_buf) - 1] = '\0'; + filename = undef_msg_buf; + lineno = 0; + } + if (stack->sym == last_sym) fprintf(stderr, "%s:%d:error: recursive dependency detected!\n", - prop->file->name, prop->lineno); + filename, lineno); if (stack->expr) { fprintf(stderr, "%s:%d:\tsymbol %s %s value contains %s\n", - prop->file->name, prop->lineno, + filename, lineno, sym->name ? sym->name : "", prop_get_type_name(prop->type), next_sym->name ? next_sym->name : ""); } else if (stack->prop) { fprintf(stderr, "%s:%d:\tsymbol %s depends on %s\n", - prop->file->name, prop->lineno, + filename, lineno, sym->name ? sym->name : "", next_sym->name ? next_sym->name : ""); } else if (sym_is_choice(sym)) { @@ -1027,7 +1051,7 @@ static void sym_check_print_recursive(struct symbol *last_sym) next_sym->name ? next_sym->name : ""); } else { fprintf(stderr, "%s:%d:\tsymbol %s is selected by %s\n", - prop->file->name, prop->lineno, + filename, lineno, sym->name ? sym->name : "", next_sym->name ? next_sym->name : ""); }