Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2143221imm; Mon, 28 May 2018 02:29:53 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr0QlCXke6OFdwwBNkGfCX/GDKxQQn6xSbZQPPyIzxSGLoFokxyD6i3YHr3wDHdGiknkEaX X-Received: by 2002:a17:902:8a95:: with SMTP id p21-v6mr13068380plo.325.1527499793583; Mon, 28 May 2018 02:29:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499793; cv=none; d=google.com; s=arc-20160816; b=L8tRdEx2Si2k2yTytZFdifD2Zq3/FjxojPeA4ANa1scxPWjh9Xd8W+eYEBRQtUCIeH DDD2YuPU7tuubO8x9xQD9VLISLEvXaAZb0JVd0h/w3yVnTdpT1XnKTr42FMVaicHIuGe xcD50xmg+NzH2AcVG6NMI0Bmm1QVUaheoffsjyvks4eIhctKU55tNs6Z0/X0SX76zapz fyimcYlXvp95GguJFwVQeAFzibHaldfCKMlJgO1XKv9ubBnvgeGOz00jGNMvKDx14ilY oUSwI3q7lNlEbi9xKTUv2H+RQkUCGt9VaPU/f98EfRdZrwthl8Vsto5HUs1ae/IISPx3 12cQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=LbVKH3YfDdo86RaBlckj7gU3H1+hfktcSEEEz/uGgcY=; b=B5XRtOpGu5R+6ZRXXskLN5vNACDXpDrcEjxJ8wnmnBpB5a9S0hLazLtm5IjyOlHYuN m8j3AVO58o2U330dywmClGscWcNwI3as62ZT9HoKxynNv9nEG2AGRi/4iYIDmvHZRHqb 46VV0DCU9Bfbo+GU8bbEb9tJ5rTj3kUhajLltNKyIMiafB5XtD3uaBqwnN3yyM/icBiP fCVvkCzAQdXWVxWnkW15PDZUgSPI4hPlrkP18d0oTvlgsyImS1cR5WGsid/GVPcmQR5d VW1lwW8PsM6zzuiQzuf6MBhLzRJjDTHkaBGvhvRa4tzR4F8XCFfENTGG9MriomuZMY1f swoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=aNSMywPA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si29320581plk.521.2018.05.28.02.29.38; Mon, 28 May 2018 02:29:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=aNSMywPA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933732AbeE1J2v (ORCPT + 99 others); Mon, 28 May 2018 05:28:51 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21628 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754334AbeE1JYR (ORCPT ); Mon, 28 May 2018 05:24:17 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInZ027506; Mon, 28 May 2018 18:22:33 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInZ027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499354; bh=LbVKH3YfDdo86RaBlckj7gU3H1+hfktcSEEEz/uGgcY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aNSMywPAxNtsGreyBwY6U1/dqGrF+LLwtOMpWTN2ZCeDnteSBvqFGMd0oBILUuuZn WNXDteNr0OkKty3mVIQwa6b9PR58IFc85hFfWZaEw00crfRy0Pq0DZibAI2r20DQqZ 1wYWT7kQhSgObelyN8TUjUl/G6+8qDpQN1Y7rhdQtKGBWXNwmEWMNHBvM1//GDLfGF LIe6nWa2yvzeRh+Tu9h3ntyh+BncRLtXrHACCXtu4ARPjp3xF8DPbw4TnIIOitGJWP oWL6RDyCbWwn7athfY/hdi9kSnASEVyuz+5ZY1+bY0fVUjFaJrl0GmO7faLIuVxwSl v6NGf7jS66M5w== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 18/31] kconfig: error out if a recursive variable references itself Date: Mon, 28 May 2018 18:21:55 +0900 Message-Id: <1527499328-13213-19-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When using a recursively expanded variable, it is a common mistake to make circular reference. For example, Make terminates the following code: X = $(X) Y := $(X) Let's detect the circular expansion in Kconfig, too. On the other hand, a function that recurses itself is a commonly-used programming technique. So, Make does not check recursion in the reference with 'call'. For example, the following code continues running eternally: X = $(call X) Y := $(X) Kconfig allows circular expansion if one or more arguments are given, but terminates when the same function is recursively invoked 1000 times, assuming it is a programming mistake. Signed-off-by: Masahiro Yamada --- Changes in v5: None Changes in v4: - Newly added Changes in v3: None Changes in v2: None scripts/kconfig/preprocess.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index 0574039..65da87f 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -229,6 +229,7 @@ struct variable { char *name; char *value; enum variable_flavor flavor; + int exp_count; struct list_head node; }; @@ -253,11 +254,22 @@ static char *variable_expand(const char *name, int argc, char *argv[]) if (!v) return NULL; + if (argc == 0 && v->exp_count) + pperror("Recursive variable '%s' references itself (eventually)", + name); + + if (v->exp_count > 1000) + pperror("Too deep recursive expansion"); + + v->exp_count++; + if (v->flavor == VAR_RECURSIVE) res = expand_string_with_args(v->value, argc, argv); else res = xstrdup(v->value); + v->exp_count--; + return res; } @@ -284,6 +296,7 @@ void variable_add(const char *name, const char *value, v = xmalloc(sizeof(*v)); v->name = xstrdup(name); + v->exp_count = 0; list_add_tail(&v->node, &variable_list); } -- 2.7.4