linux-kbuild.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] kconfig: avoid an infinite loop in oldconfig/syncconfig
@ 2023-08-05  9:57 Yoann Congal
  2023-08-07 19:25 ` Masahiro Yamada
  0 siblings, 1 reply; 4+ messages in thread
From: Yoann Congal @ 2023-08-05  9:57 UTC (permalink / raw)
  To: Masahiro Yamada, linux-kbuild; +Cc: linux-kernel, Yoann Congal

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] kconfig: avoid an infinite loop in oldconfig/syncconfig
  2023-08-05  9:57 [PATCH v2] kconfig: avoid an infinite loop in oldconfig/syncconfig Yoann Congal
@ 2023-08-07 19:25 ` Masahiro Yamada
  2023-08-07 20:25   ` Randy Dunlap
  0 siblings, 1 reply; 4+ messages in thread
From: Masahiro Yamada @ 2023-08-07 19:25 UTC (permalink / raw)
  To: Yoann Congal; +Cc: linux-kbuild, linux-kernel

On Sat, Aug 5, 2023 at 6:57 PM Yoann Congal <yoann.congal@smile.fr> wrote:
>
> 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
>


It is strange (and consistent) to bail out
only for particular types.


I would change the code simply as follows:



--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -76,8 +76,10 @@ static void strip(char *str)
 /* Helper function to facilitate fgets() by Jean Sacren. */
 static void xfgets(char *str, int size, FILE *in)
 {
-       if (!fgets(str, size, in))
+       if (!fgets(str, size, in)) {
                fprintf(stderr, "\nError in reading or end of file.\n");
+               exit(1);
+       }

        if (!tty_stdio)
                printf("%s", str);






yes "" | make config

will succeed.



make config < /dev/null

will fail.





People expecting the closed stdin to succeed
may start complaining, but I believe
they must fix their wrong scripts.


-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] kconfig: avoid an infinite loop in oldconfig/syncconfig
  2023-08-07 19:25 ` Masahiro Yamada
@ 2023-08-07 20:25   ` Randy Dunlap
  2023-09-12 15:51     ` Yoann Congal
  0 siblings, 1 reply; 4+ messages in thread
From: Randy Dunlap @ 2023-08-07 20:25 UTC (permalink / raw)
  To: Masahiro Yamada, Yoann Congal; +Cc: linux-kbuild, linux-kernel



On 8/7/23 12:25, Masahiro Yamada wrote:
> On Sat, Aug 5, 2023 at 6:57 PM Yoann Congal <yoann.congal@smile.fr> wrote:
>>
>> 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
>>
> 
> 
> It is strange (and consistent) to bail out
> only for particular types.
> 

It's still very helpful to know the symbol name that is causing
the issue.

> 
> I would change the code simply as follows:
> 
> 
> 
> --- a/scripts/kconfig/conf.c
> +++ b/scripts/kconfig/conf.c
> @@ -76,8 +76,10 @@ static void strip(char *str)
>  /* Helper function to facilitate fgets() by Jean Sacren. */
>  static void xfgets(char *str, int size, FILE *in)
>  {
> -       if (!fgets(str, size, in))
> +       if (!fgets(str, size, in)) {
>                 fprintf(stderr, "\nError in reading or end of file.\n");
> +               exit(1);
> +       }
> 
>         if (!tty_stdio)
>                 printf("%s", str);
> 
> 
> 
> 
> 
> 
> yes "" | make config
> 
> will succeed.
> 
> 
> 
> make config < /dev/null
> 
> will fail.
> 
> 
> 
> 
> 
> People expecting the closed stdin to succeed
> may start complaining, but I believe
> they must fix their wrong scripts.
> 
> 

-- 
~Randy

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] kconfig: avoid an infinite loop in oldconfig/syncconfig
  2023-08-07 20:25   ` Randy Dunlap
@ 2023-09-12 15:51     ` Yoann Congal
  0 siblings, 0 replies; 4+ messages in thread
From: Yoann Congal @ 2023-09-12 15:51 UTC (permalink / raw)
  To: Randy Dunlap, Masahiro Yamada; +Cc: linux-kbuild, linux-kernel

Hi,

On 8/7/23 22:25, Randy Dunlap wrote:
> On 8/7/23 12:25, Masahiro Yamada wrote:
>> It is strange (and consistent) to bail out
>> only for particular types.
> 
> It's still very helpful to know the symbol name that is causing
> the issue.
> 
>>
>> I would change the code simply as follows:
>> *snip*>>
>> yes "" | make config
>>
>> will succeed.
>>
>> make config < /dev/null
>>
>> will fail.
>>
>> People expecting the closed stdin to succeed
>> may start complaining, but I believe
>> they must fix their wrong scripts.

I've sent a v3 trying to fuse both of your suggestions.

Regards,
-- 
Yoann Congal
Smile ECS - Tech Expert

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-09-12 15:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-05  9:57 [PATCH v2] kconfig: avoid an infinite loop in oldconfig/syncconfig Yoann Congal
2023-08-07 19:25 ` Masahiro Yamada
2023-08-07 20:25   ` Randy Dunlap
2023-09-12 15:51     ` Yoann Congal

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).