linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yoann Congal <yoann.congal@smile.fr>
To: Masahiro Yamada <masahiroy@kernel.org>, linux-kbuild@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Yoann Congal <yoann.congal@smile.fr>
Subject: [PATCH v2] kconfig: avoid an infinite loop in oldconfig/syncconfig
Date: Sat,  5 Aug 2023 11:57:09 +0200	[thread overview]
Message-ID: <20230805095709.6717-1-yoann.congal@smile.fr> (raw)

Exit on error when asking for value that has an invalid default value
and stdin has reached EOF. This 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 <yoann.congal@smile.fr>
---
v1->v2:
 * Improve coding style
 * Put more info in the commit message 

 scripts/kconfig/conf.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index 7cf63261d951c..8f32cbbce4805 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -377,8 +377,16 @@ static int conf_string(struct menu *menu)
 			line[strlen(line)-1] = 0;
 			def = line;
 		}
-		if (def && sym_set_string_value(sym, def))
+		if (def && sym_set_string_value(sym, def)) {
 			return 0;
+		} else {
+			if (feof(stdin) && !sym_string_valid(sym, sym_get_string_value(sym))) {
+				fprintf(stderr,
+					"Symbol %s has invalid default value and stdin reached EOF\n",
+					sym->name);
+				exit(1);
+			}
+		}
 	}
 }
 
-- 
2.30.2


             reply	other threads:[~2023-08-05  9:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-05  9:57 Yoann Congal [this message]
2023-08-07 19:25 ` [PATCH v2] kconfig: avoid an infinite loop in oldconfig/syncconfig Masahiro Yamada
2023-08-07 20:25   ` Randy Dunlap
2023-09-12 15:51     ` Yoann Congal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230805095709.6717-1-yoann.congal@smile.fr \
    --to=yoann.congal@smile.fr \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).