From patchwork Tue Oct 31 11:16:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoann Congal X-Patchwork-Id: 160065 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b90f:0:b0:403:3b70:6f57 with SMTP id t15csp159447vqg; Tue, 31 Oct 2023 04:17:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFVQmSZA8apwu3RDpEOafWy/SKTGi+ILTa+osudGYPkY/IYW1AmPSAjw0DOkjNtdOIqD8qt X-Received: by 2002:a05:6a21:778d:b0:180:dc62:20cb with SMTP id bd13-20020a056a21778d00b00180dc6220cbmr2495761pzc.38.1698751062705; Tue, 31 Oct 2023 04:17:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698751062; cv=none; d=google.com; s=arc-20160816; b=ze+DUTUN5BRstkESYkBqSR4tV9owmeRAH9PLrPaDM49rmapHpJU9z/IyK/C3GA+sn4 7HxN3VgOQ0MCLCngSI4yR4j+p/0pJNkl0ecGcYArS61JuOjnlnUyx4oTThYOs7k8rh2g rwwrKpc9IGwjm/hIR+NjqVkXmG0d76BAu1bTMngZooL8L/Lj7hkMJgXvdtoIGdzbJdig EhkFpWvdXbXXxWJJy/pcoMMhfxEj53Oc0TUXwlbZNK28MCpp0NsEq84DixyetOuoN1lt AHT6VN2Wi38F1d+LPmFdzmrk/bI4ZF71RnPr8BeqAxj25zDlGckIe5a1UF5CtAmscIeE 2jqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=w4v8a5RiHMYlglwAdgrZyHV3KIcl5PxmltDe1hiSZ5M=; fh=1420IjStZLzWCTSQO2gSJ1UGIHHkPdp+/7Dfj3ndDNc=; b=k6EfyPuxOz8yv+MKehoBwqF8BQqcYD4QzLWCOY3i5Gd49zqs5AKAilEJVMQ3ZiGvV+ 9B+yUV4qZVRTNPcUrrhHZ4cEkTFm9Z17H10qS18IuMqUKZh48ND7MZSAIrQpyYhgvpNc lHJHvVn6smOY1E99oVck9fnN+BIBg2XtJxOe44CCA2zcTKQh4PXEJPyUryHEa5ImDaCz 76Ioud1DLR0V+ooX52hGU62VyC1gEI9OKL4y2lVKDMACgW6p2lnLo2RVQp2NlPQDxj8o 1zO9P6KivN422XrL31FB+cICUF5nGWmG2Zc41L84VbMBIbQb0jltNvwzMmiFiwVvCj6i 1bdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@smile-fr.20230601.gappssmtp.com header.s=20230601 header.b=WJx19JUv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id o18-20020a170902d4d200b001c9d7d8860fsi872264plg.485.2023.10.31.04.17.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 04:17:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@smile-fr.20230601.gappssmtp.com header.s=20230601 header.b=WJx19JUv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 124248050638; Tue, 31 Oct 2023 04:17:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233230AbjJaLRT (ORCPT + 34 others); Tue, 31 Oct 2023 07:17:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229974AbjJaLRR (ORCPT ); Tue, 31 Oct 2023 07:17:17 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADB94C2 for ; Tue, 31 Oct 2023 04:17:13 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-9d10f94f70bso510038966b.3 for ; Tue, 31 Oct 2023 04:17:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smile-fr.20230601.gappssmtp.com; s=20230601; t=1698751032; x=1699355832; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=w4v8a5RiHMYlglwAdgrZyHV3KIcl5PxmltDe1hiSZ5M=; b=WJx19JUvYylr/rePwIlsbglrHYMDlSA5sfnuSL6EmAowSbdSUT3Fd+/XXxlrZfhUsj J/cszZP4AYXS61DCreqXv3AqPWzkPNXFJLT+sT8faZ2ZJy53NwvmO5Hb9ETw4q5MXwNh IbHL3gIWtKxDvqu6hI2qBjZeMd8PGvS0H3eYZ9e/Ss9h/Cxl7Okfl20j9kLYjlb0CPuU PYCJ6a+fnJp6U4VJ5uEK4UrzeNLv89S6hbXx2zHl0lxgp7nk4XNwkyAiWvF1Bye+T5Ni AmBXXyCcp53cjjrigM3chteIjYRIOaYtwOWIVyMhYjj31j2aWLD0l4nuc0Yx5rcOAYNJ HinQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698751032; x=1699355832; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=w4v8a5RiHMYlglwAdgrZyHV3KIcl5PxmltDe1hiSZ5M=; b=jRVTaxWo2KtvbmwnJQYrqkhVfQpZmo/a/ovstab49ZxfXc4Itk8PW6YHKcD0B7M7hQ rbqm+/xZ1wASj+CWWfrSzNMh0G4NuLbBxLODJeKKoQB/nrtDlKxaj1ANxn81dLEtmIC8 PTdqv9VzuGeb9p6khp/6OGESYaS4Lc3fHn97/LI/dA4WFysgKrD4zrrduhSmU3yve9ld R/m90Ybbc4Y1fXXTCBIho7GMBVV0mOtK1b5C73YI0l5WHGv3VMWRTsEVFQpZv7HQNPW/ hCEskOn4FOnHUV/Xk/O6pRujOjHMwAcFMThx1V5oetWT6E6CJed2rGDGqtE9MIo/iwCV 5mag== X-Gm-Message-State: AOJu0Yxi+37Jf5S0GzuJ0b4t1/9XAk6lijn75emKSdUJrDSjhvHvQO1y nW8Q8itJQV8t0tz8bWRS/gXD2A== X-Received: by 2002:a17:907:2da9:b0:9b2:982e:339a with SMTP id gt41-20020a1709072da900b009b2982e339amr9426712ejc.22.1698751031721; Tue, 31 Oct 2023 04:17:11 -0700 (PDT) Received: from P-ASN-ECS-830T8C3.numericable.fr ([89.159.1.53]) by smtp.gmail.com with ESMTPSA id oy11-20020a170907104b00b0099cc36c4681sm795606ejb.157.2023.10.31.04.17.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 04:17:11 -0700 (PDT) From: Yoann Congal To: Masahiro Yamada , linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Randy Dunlap , Yoann Congal , Brandon Maier Subject: [PATCH v4] kconfig: avoid an infinite loop in oldconfig/syncconfig Date: Tue, 31 Oct 2023 12:16:47 +0100 Message-Id: <20231031111647.111093-1-yoann.congal@smile.fr> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 31 Oct 2023 04:17:25 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781269594570301654 X-GMAIL-MSGID: 1781269594570301654 Exit on error when asking for value and reading stdin returns an error (mainly if it has reached EOF or is closed). This infinite loop happens in particular for hex/int configs without an explicit default value. Previously, this case would loop: * oldconfig prompts for the value but stdin has reached EOF * It gets the global default value : an empty string * This is not a valid hex/int value so it prompts again, hence the infinite loop. This case happens with a configuration like this (a hex config without a valid default value): config TEST_KCONFIG hex "Test KConfig" # default 0x0 And using: make oldconfig < /dev/null This was discovered when working on Yocto bug[0] on a downstream kconfig user (U-boot) [0]: https://bugzilla.yoctoproject.org/show_bug.cgi?id=14136 Signed-off-by: Yoann Congal Tested-by: Brandon Maier --- v3->v4: * Added Brandon Maier's "Tested-by". Thanks! v2->v3: * Simplify the patch by fusing comments of : * Masahiro Yamada : Exit as soon as reading stdin hits an error * Randy Dunlap : Display the name of the currently read symbol v1->v2: * Improve coding style * Put more info in the commit message scripts/kconfig/conf.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index 33d19e419908..68f0c649a805 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -74,13 +74,17 @@ static void strip(char *str) } /* Helper function to facilitate fgets() by Jean Sacren. */ -static void xfgets(char *str, int size, FILE *in) +static int xfgets(char *str, int size, FILE *in) { + int ret = 0; + if (!fgets(str, size, in)) - fprintf(stderr, "\nError in reading or end of file.\n"); + ret = -1; if (!tty_stdio) printf("%s", str); + + return ret; } static void set_randconfig_seed(void) @@ -339,7 +343,10 @@ static int conf_askvalue(struct symbol *sym, const char *def) /* fall through */ default: fflush(stdout); - xfgets(line, sizeof(line), stdin); + if (xfgets(line, sizeof(line), stdin) != 0) { + fprintf(stderr, "Error while reading value of symbol \"%s\"\n", sym->name); + exit(1); + } break; } @@ -521,7 +528,11 @@ static int conf_choice(struct menu *menu) /* fall through */ case oldaskconfig: fflush(stdout); - xfgets(line, sizeof(line), stdin); + if (xfgets(line, sizeof(line), stdin) != 0) { + fprintf(stderr, "Error while reading value of symbol \"%s\"\n", + sym->name); + exit(1); + } strip(line); if (line[0] == '?') { print_help(menu);