]> git.itanic.dy.fi Git - linux-stable/commitdiff
kconfig: fix infinite loop when expanding a macro at the end of file
authorMasahiro Yamada <masahiroy@kernel.org>
Fri, 2 Feb 2024 15:57:59 +0000 (00:57 +0900)
committerSasha Levin <sashal@kernel.org>
Tue, 26 Mar 2024 22:17:29 +0000 (18:17 -0400)
[ Upstream commit af8bbce92044dc58e4cc039ab94ee5d470a621f5 ]

A macro placed at the end of a file with no newline causes an infinite
loop.

[Test Kconfig]
  $(info,hello)
  \ No newline at end of file

I realized that flex-provided input() returns 0 instead of EOF when it
reaches the end of a file.

Fixes: 104daea149c4 ("kconfig: reference environment variables directly and remove 'option env='")
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
scripts/kconfig/lexer.l

index cc386e44368346c2309d2f60aab3cad10a5cefb0..2c2b3e6f248caff0b39faa5ece05b82a573879f6 100644 (file)
@@ -302,8 +302,11 @@ static char *expand_token(const char *in, size_t n)
        new_string();
        append_string(in, n);
 
-       /* get the whole line because we do not know the end of token. */
-       while ((c = input()) != EOF) {
+       /*
+        * get the whole line because we do not know the end of token.
+        * input() returns 0 (not EOF!) when it reachs the end of file.
+        */
+       while ((c = input()) != 0) {
                if (c == '\n') {
                        unput(c);
                        break;