From patchwork Mon May 28 09:21:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 137058 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2595313lji; Mon, 28 May 2018 02:28:55 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrIarygQRaff69wM7WKRsxFpHTb0sZwDVtIVSt6a/nGTSOF+Vxid1uobVkYM9Tk/4bjd2rR X-Received: by 2002:a63:ba1c:: with SMTP id k28-v6mr10028570pgf.179.1527499735133; Mon, 28 May 2018 02:28:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499735; cv=none; d=google.com; s=arc-20160816; b=zW5qTgqfcBAjJQfXIcJi40sH255wwM6XmBNJ1OyNh/O0nJzCiqfM7mV3JNQiyL9ODp APEpjLe6L6cf/ggk46QK7sEvMOJxRxFRSkOyVy+Mq9ZsRVa3gV1uNzwQyFbPX5mYSaW5 FiZ0z+Bv5C2dv6+1G9P1cg4AZpYBKOFwwmwNeCiI+bW32kG8hOqwH7Q01HCs3IznC24R 2ahYLbqJdUIn5AG+GV3yItBS8czOqZAMiZvhAsQmnQ5zYo/Hx51nCOuedjT8xj+ev56W POKhkkWm/Ca534mZ64ZjAHez8BoGwfiY5mnpJhF57x/8z18XZZIdoyu/7rbz0bDeBeny oS0w== 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 g13-v6si23861279pgn.146.2018.05.28.02.28.54; Mon, 28 May 2018 02:28:55 -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 S933888AbeE1J2w (ORCPT + 30 others); Mon, 28 May 2018 05:28:52 -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(+) -- 2.7.4 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); }