Re: [PATCH 2/2] kconfig/nconf: prevent segfault on empty menu

Nir Tzachar
2011-07-10T10:32:48Z

Hello.

On Sun, Jul 10, 2011 at 10:27 AM, Arnaud Lacombe <lacombar@gmail.com> wrote:
> nconf does not check the validity of the current menu when help is requested
> (with either <F2>, '?' or 'h'). This leads to a NULL pointer dereference when an
> empty menu is encountered.
>
> The following reduced testcase exposes the problem:
>
> config DEP
>        bool
>
> menu "FOO"
>
> config BAR
>        bool "BAR"
>        depends on DEP
>
> endmenu
>
> Issue will happen when entering menu "FOO" and requesting help.
>
> nconf is the only front-end which do not filter the validity of the current
> menu. Such filter can not really happen beforehand as other key which does not
> deals with the current menu might be entered by the user, so just bails out
> earlier if we encounter an invalid menu.

I do not believe the correct solution is silently ignoring the user's
key presses. I think the correct behavior would be to display a
nohelp_text window.

something like this (untested):
show_scroll_win(main_window, nohelp_text);

The other patches in the series seem gr8.

Cheers.

> Cc: Nir Tzachar <nir.tzachar@gmail.com>
> Cc: Andrej Gelenberg <andrej.gelenberg@udo.edu>
> Reported-by: Andrej Gelenberg <andrej.gelenberg@udo.edu>
> Signed-off-by: Arnaud Lacombe <lacombar@gmail.com>
> ---
>  scripts/kconfig/nconf.c |    7 ++++++-
>  1 files changed, 6 insertions(+), 1 deletions(-)
>
> diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c
> index 24fc79a..eb9e49d 100644
> --- a/scripts/kconfig/nconf.c
> +++ b/scripts/kconfig/nconf.c
> @@ -1222,7 +1222,12 @@ static void conf_message_callback(const char *fmt, va_list ap)
>
>  static void show_help(struct menu *menu)
>  {
> -       struct gstr help = str_new();
> +       struct gstr help;
> +
> +       if (!menu)
> +               return;
> +
> +       help = str_new();
>        menu_get_ext_help(menu, &help);
>        show_scroll_win(main_window, _(menu_get_prompt(menu)), str_get(&help));
>        str_free(&help);
> --
> 1.7.3.4.574.g608b.dirty
>
>