Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp3689886rwi; Wed, 2 Nov 2022 01:51:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM78FDw48D3pSJJ37pBhjNvBs9cSxXtKajwNSh4gSatGMP4haMXwIivMmnAfmKzQcd6rLw93 X-Received: by 2002:a17:903:11c7:b0:178:af17:e93e with SMTP id q7-20020a17090311c700b00178af17e93emr23437169plh.78.1667379091192; Wed, 02 Nov 2022 01:51:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667379091; cv=none; d=google.com; s=arc-20160816; b=U6uk+Fx6wXp1iaR6GQ/3Wnc2z8tj2DrDtirofVYADW9q8uz3dQDlOFLef78g0t4zoO mmCsEGAW+usa//2x76Sc+k4dCXRQtyQG78OVOOnhABm3bvZKRC5ZsXzcPFjENcEmseGX DxSSXd5wMJY68XhAGRFrvB6PPXSaubwgyLkUBm/eyX54VxIXLrZcKmEWLwM2NQSmnwff Qm9xFlzUF9xkk5rRBmI3roiwgQePvklSewnsQGQoEjl9POC7lkLbQ65RME4Bt0XohIz+ lSug1KKV2j6v6JmDlf/9rJEhKxjuJHi6+fl+j6OV2wDkQGPux04GbjckZMg+xkL1At7p fa4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature:dkim-filter; bh=dDwYrbtyAzndbrpCPMQ4b/+qE79Xq0pwlBypNXvEf3A=; b=Mx4GnG6xh+N+tNxm1iN0xB6hU40Z2qC5q/S+GHyFwXiq/dUKiRAOBQvdn/GyT7xdfv imAH91kOy+6JKSaJqt93dJIqAAYje7ycMIh0n7BkIb7COOc4YWN4RJex1PTxD6WViRKh gsIQNh+SGgTWKpEOjvRSbqSmJRGs+gHbAtXh85nGKARmzfbgSHKmrAmha2o57CwmIj5Z aO/ts78LHl/37Vy6NtvS53hdS8eGRqnC7NNFQEXIsUm4Kl6z0BjVhDFLDT7EvKIhLa4t dOyssxO1MHqB9Hqqwm7+GT6q6Y+Qi83CJd1zh3C0JJyh0zsbibqolXrYczl1DpAD5dSj nJOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b="hOiuqSR/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m12-20020a170902d18c00b0017b977d1b7bsi13031747plb.32.2022.11.02.01.51.18; Wed, 02 Nov 2022 01:51:31 -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; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b="hOiuqSR/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230400AbiKBIgf (ORCPT + 97 others); Wed, 2 Nov 2022 04:36:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229518AbiKBIgc (ORCPT ); Wed, 2 Nov 2022 04:36:32 -0400 Received: from conssluserg-03.nifty.com (conssluserg-03.nifty.com [210.131.2.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F181A19C; Wed, 2 Nov 2022 01:36:31 -0700 (PDT) Received: from mail-oi1-f175.google.com (mail-oi1-f175.google.com [209.85.167.175]) (authenticated) by conssluserg-03.nifty.com with ESMTP id 2A28aEJ8031478; Wed, 2 Nov 2022 17:36:15 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-03.nifty.com 2A28aEJ8031478 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1667378175; bh=dDwYrbtyAzndbrpCPMQ4b/+qE79Xq0pwlBypNXvEf3A=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=hOiuqSR/T/VgZje1tOrN54QWDUjrUnwK7i0VH4Dn58fTfeskL0xqmHUU+sxeap0vg hQpcvuvxoTaHcXsKSZELTb+wts+8t4i5vNZvPchML3PlPfoYtdwhJ73cWoQAjVYzbn +ckPsMAc90obxKLGkhfble2BYlZ/KK56u86OQMliiyYkayy7+ZDTqJ4+N40quGfbY+ aNUlk6muhgm8QeAVx0TlxOy7d4a2usyjDkljMi1QpzZmvICXqcNiQIl3XpFK/UpNxt ykFm/j/F/V/a5d5N3t4bc4mrrkcRu6PIrQL64LmvzVadCUrAZyNV1sE3lKaejCSM3C huEWXbEPO3Oqg== X-Nifty-SrcIP: [209.85.167.175] Received: by mail-oi1-f175.google.com with SMTP id s206so18533463oie.3; Wed, 02 Nov 2022 01:36:15 -0700 (PDT) X-Gm-Message-State: ACrzQf15/rspUDvsD5fZCd3K9/AJZrQi3ggDXluLhUlpWVLvDY1ypJRb +aAZD2tWGxuML7FMDJabcEamhRzHiKuoXl+uzEs= X-Received: by 2002:a05:6808:13cf:b0:35a:3617:d5da with SMTP id d15-20020a05680813cf00b0035a3617d5damr2199262oiw.287.1667378174040; Wed, 02 Nov 2022 01:36:14 -0700 (PDT) MIME-Version: 1.0 References: <20221023191055.85098-1-masahiroy@kernel.org> <8c04e9bbc8d48946c60ff56ef7f20bef74e3c401.camel@pengutronix.de> In-Reply-To: <8c04e9bbc8d48946c60ff56ef7f20bef74e3c401.camel@pengutronix.de> From: Masahiro Yamada Date: Wed, 2 Nov 2022 17:35:37 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] kconfig: fix segmentation fault in menuconfig search To: Johannes Zink Cc: linux-kbuild@vger.kernel.org, Ariel Marcovitch , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no 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 On Tue, Nov 1, 2022 at 2:31 AM Johannes Zink wrote: > > 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 Applied to linux-kbuild/fixes. > > --- > > > > 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 | > -- Best Regards Masahiro Yamada