Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp1074447rwi; Mon, 31 Oct 2022 10:52:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Rn9X5z6tTJasrNZ+8zKxs47gIMbQuOMjZnkIAi8Zs4aeJhRO5YjMz5kNHSyrbtw2+XtW9 X-Received: by 2002:a17:907:782:b0:740:7120:c6e7 with SMTP id xd2-20020a170907078200b007407120c6e7mr13948434ejb.313.1667238727935; Mon, 31 Oct 2022 10:52:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667238727; cv=none; d=google.com; s=arc-20160816; b=PEDRVGPpyCywyTRTAt0FumN6SdvtjcdxtxqUIqIMsfXx5wWnk0hCVVIpe6H5wf0F3y nLlH8z1VXv4gbs9XEG9KGvG8uv63n2faOxjr7PafA6lic8hXQLZKtKxWLTZ42DLNfSPq 43UyR3UYvQViCMQhhduXMyu8j9SB2nUlwdfB4yBAs+6L3vM6FD/7NkqAUGmwzj9y70pz rl9NIqnEUjhVyYtPCB2fPbVumNld+ZN+FnT+rbqwBEcb/zjZZX18Ujn2J9cwNbWpHvI8 x7lHFge0Z30vaDbUVz3jKQUybnLZSiO0gPRsbPfqTegprrGj6zz/rvhB1ndLBwPieXNO tpug== 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 :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=JNd0V4b8SU3UTCAGQfgNOGjn8CCNuATujDX93qZ1abU=; b=mOzp4Jc5h57WInytT6ReSrpWcNE+FKXuTLuFFaswGfIIsMTPrWs1/MF9H06y5/zs/f lT+tbS8YabJ5pxNVLPTmgZrhO1tZZTKGX9v+yqfBVUJjoxjd0X4zvSIyXaaOO+ZVIw/R +f5lDGrF1WI5MUauzHIHGiBILKTTkDutlfQe+bcKHWSfuqZ0tmGQ+xDPekQeDfje7pt2 7C6cn8uXxkZ1yM/sNkz5mSRPe7g/MVCuX6f/9PqttQVOy7ldkHiEfh6jg+l3DzzSpBOW YZ4CrdwlAJJbYbvTzLRbzODa35fFgqzZO6gtl23uk5Aa0UH0i2A1f2j/LtzU0fLG72/C qe3w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oz13-20020a170906cd0d00b00782a33f2850si6682760ejb.736.2022.10.31.10.51.44; Mon, 31 Oct 2022 10:52:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231656AbiJaRbd (ORCPT + 98 others); Mon, 31 Oct 2022 13:31:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229727AbiJaRbb (ORCPT ); Mon, 31 Oct 2022 13:31:31 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 927E7DF31 for ; Mon, 31 Oct 2022 10:31:30 -0700 (PDT) Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=irc.pengutronix.de) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1opYdB-00006r-LR; Mon, 31 Oct 2022 18:31:25 +0100 Message-ID: <8c04e9bbc8d48946c60ff56ef7f20bef74e3c401.camel@pengutronix.de> Subject: Re: [PATCH] kconfig: fix segmentation fault in menuconfig search From: Johannes Zink To: Masahiro Yamada , linux-kbuild@vger.kernel.org Cc: Ariel Marcovitch , linux-kernel@vger.kernel.org Date: Mon, 31 Oct 2022 18:31:20 +0100 In-Reply-To: <20221023191055.85098-1-masahiroy@kernel.org> References: <20221023191055.85098-1-masahiroy@kernel.org> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.3-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: j.zink@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Masahiro, On Mon, 2022-10-24 at 04:10 +0900, Masahiro Yamada wrote: > Since commit d05377e184fc ("kconfig: Create links to main menu items > in search"), menuconfig shows a jump key next to "Main menu" if the > nearest visible parent is the rootmenu. If you press that jump key, > menuconfig crashes with a segmentation fault. > > For example, do this: > >   $ make ARCH=arm64 allnoconfig menuconfig > > Press '/' to search for the string "ACPI". Press '1' to choose > "(1) Main menu". Then, menuconfig crashed with a segmentation fault. > > The following code in search_conf() > >     conf(targets[i]->parent, targets[i]); > > results in NULL pointer dereference because targets[i] is the > rootmenu, > which does not have a parent. > > Commit d05377e184fc tried to fix the issue of top-level items not > having > a jump key, but adding the "Main menu" was not the right fix. > > The correct fix is to show the searched item itself. This fixes > another > weird behavior described in the comment block. > > Fixes: d05377e184fc ("kconfig: Create links to main menu items in > search") > Reported-by: Johannes Zink > Signed-off-by: Masahiro Yamada Sorry for the delay, I eventually found time to test your patch, and it fixes the issue I reported. Thank you for helping out, feel free to add my Tested-by: Johannes Zink > --- > >  scripts/kconfig/menu.c | 23 ++++------------------- >  1 file changed, 4 insertions(+), 19 deletions(-) > > diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c > index 62b6313f51c8..109325f31bef 100644 > --- a/scripts/kconfig/menu.c > +++ b/scripts/kconfig/menu.c > @@ -722,8 +722,8 @@ static void get_prompt_str(struct gstr *r, struct > property *prop, >         if (!expr_eq(prop->menu->dep, prop->visible.expr)) >                 get_dep_str(r, prop->visible.expr, "  Visible if: "); >   > -       menu = prop->menu->parent; > -       for (i = 0; menu && i < 8; menu = menu->parent) { > +       menu = prop->menu; > +       for (i = 0; menu != &rootmenu && i < 8; menu = menu->parent) > { >                 bool accessible = menu_is_visible(menu); >   >                 submenu[i++] = menu; > @@ -733,16 +733,7 @@ static void get_prompt_str(struct gstr *r, > struct property *prop, >         if (head && location) { >                 jump = xmalloc(sizeof(struct jump_key)); >   > -               if (menu_is_visible(prop->menu)) { > -                       /* > -                        * There is not enough room to put the hint > at the > -                        * beginning of the "Prompt" line. Put the > hint on the > -                        * last "Location" line even when it would > belong on > -                        * the former. > -                        */ > -                       jump->target = prop->menu; > -               } else > -                       jump->target = location; > +               jump->target = location; >   >                 if (list_empty(head)) >                         jump->index = 0; > @@ -758,13 +749,7 @@ static void get_prompt_str(struct gstr *r, > struct property *prop, >                 menu = submenu[i]; >                 if (jump && menu == location) >                         jump->offset = strlen(r->s); > - > -               if (menu == &rootmenu) > -                       /* The real rootmenu prompt is ugly */ > -                       str_printf(r, "%*cMain menu", j, ' '); > -               else > -                       str_printf(r, "%*c-> %s", j, ' ', > menu_get_prompt(menu)); > - > +               str_printf(r, "%*c-> %s", j, ' ', > menu_get_prompt(menu)); >                 if (menu->sym) { >                         str_printf(r, " (%s [=%s])", menu->sym->name > ? >                                 menu->sym->name : "", -- Pengutronix e.K. | Johannes Zink | Steuerwalder Str. 21 | https://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686| Fax: +49-5121-206917-5555 |