Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp90290pxb; Thu, 15 Apr 2021 23:58:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTOPg7ohTExDiXrwWkNlCZqTfrUm1HCJqpRfx2eAI9smF6KBfGSc8ZVENIsRurlJRXS5tM X-Received: by 2002:aa7:946b:0:b029:24c:57ea:99bf with SMTP id t11-20020aa7946b0000b029024c57ea99bfmr6751644pfq.63.1618556314853; Thu, 15 Apr 2021 23:58:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618556314; cv=none; d=google.com; s=arc-20160816; b=TmG49NdfIUR6NUXqOlw9Cy8zPduAZeoanpk6qi8arKt5ZfFhoj7ntsArmkkDuhqhDK B+0cE0Yg3uZROM6zYD2DQgwrDoqiht6qU1iFDzJCPqS8WOymklRAqa3tHb/zXb5gkiAZ FqPyizcokee1A7T5gap4qiXv0V5+cIqYTPw9QtwID0JQIQYb7kkuzAH+yzYv8OrXRLR+ ksT9ElHz7iW5oJT4vGN1m9KlBeJWh+5F2ANqG4LwYn2bPgobTtSpli4tRM2AFRRNSU6u VHrdQ4fFm3sjBnY9J1RriqGEkITr52a+wyoL0/WbCdK3nkerEYVCUOXBH0zHyeZ3oBzo FIZg== 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=iFOikycyQ7i5uJ+3y6p8wEYNef3YAETSQnRFp2InNPU=; b=mzLejsCgQWyUBc4Mkd+D3p0keEDpNGC6+/LLyTe/3PHRoiayFfprGy0ZE6oKkR/HA0 oUIWcr4d6sFCx6luDxrIJPsicaXPYf1dvKdKSGZSP21EztKE1q6Zdg9xEdMmebgyoVgI Qa2Vcybu2mvJt5gpbyrOQJiSueD5LiuyTpYIhKwXKJghED6yh9b3Fty3SjY+rwAnTQ3y rreNr6EfjGX3NJud57F5OmaB1ab6z4NZNJF4nYt2Fl0De/cuwqz+/lTsTnn/jX+aRNax P858JC612f/KlqopK5dq9FD1cDEPnjuze9t1w+7qSfEr8Gj/WIY3fSFmOl/b3ss6bfXK CvDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=vqMORC5u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h30si5846133pgl.437.2021.04.15.23.58.22; Thu, 15 Apr 2021 23:58:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=vqMORC5u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S238515AbhDPFlo (ORCPT + 99 others); Fri, 16 Apr 2021 01:41:44 -0400 Received: from conssluserg-06.nifty.com ([210.131.2.91]:26771 "EHLO conssluserg-06.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231598AbhDPFlo (ORCPT ); Fri, 16 Apr 2021 01:41:44 -0400 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (authenticated) by conssluserg-06.nifty.com with ESMTP id 13G5epDP031255 for ; Fri, 16 Apr 2021 14:40:51 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-06.nifty.com 13G5epDP031255 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1618551652; bh=iFOikycyQ7i5uJ+3y6p8wEYNef3YAETSQnRFp2InNPU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=vqMORC5uwkR0SD06BZH/Md9UniYKVyNm/oOVQ9a9g5+JusU6ofzdm6jVVGL+OIBgC LwsJRqAxJlukIdDEZCML9/lA4sbEkefUfmvDa03SeQ+uGBX17osZhjsfytKovrk9+G 77VZN5q1HA3O135Z6op2+afBIIgxfAIr0THlu26MbuCWYG56kVmpW7LqJTusxF2bbE hpgTvu1u2Vk5BRjK0nU+Oo9u+mQ9qeIMKC5MQKVF3qp+vNrd6LNeLgXC0Z6n5cL8xG Mq6AneWA+ahyP5Skc+TASfOXYPTlbIAZbq2uRfoT0n+og1pa5Sx6CaRsKQibgIMvAs 2c1gOVn4AT7fA== X-Nifty-SrcIP: [209.85.210.179] Received: by mail-pf1-f179.google.com with SMTP id d124so17585844pfa.13 for ; Thu, 15 Apr 2021 22:40:51 -0700 (PDT) X-Gm-Message-State: AOAM532EyaLi9bCehHZk4VR4jB/4JU8u892Cg3/FtpNldsQYE6C7U5mS ms/Fx5UmRs1KAy9vrFCpo0lpzLryBlYuukzsvQU= X-Received: by 2002:a65:45cf:: with SMTP id m15mr6561675pgr.7.1618551650955; Thu, 15 Apr 2021 22:40:50 -0700 (PDT) MIME-Version: 1.0 References: <20210327120155.500-1-ionic@ionic.de> <20210415072803.16338-1-ionic@ionic.de> In-Reply-To: <20210415072803.16338-1-ionic@ionic.de> From: Masahiro Yamada Date: Fri, 16 Apr 2021 14:40:13 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3] kconfig: nconf: stop endless search loops To: Mihai Moldovan Cc: Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 15, 2021 at 4:28 PM Mihai Moldovan wrote: > > If the user selects the very first entry in a page and performs a > search-up operation, or selects the very last entry in a page and > performs a search-down operation that will not succeed (e.g., via > [/]asdfzzz[Up Arrow]), nconf will never terminate searching the page. > > The reason is that in this case, the starting point will be set to -1 > or n, which is then translated into (n - 1) (i.e., the last entry of > the page) or 0 (i.e., the first entry of the page) and finally the > search begins. This continues to work fine until the index reaches 0 or > (n - 1), at which point it will be decremented to -1 or incremented to > n, but not checked against the starting point right away. Instead, it's > wrapped around to the bottom or top again, after which the starting > point check occurs... and naturally fails. > > My original implementation added another check for -1 before wrapping > the running index variable around, but Masahiro Yamada pointed out that > the actual issue is that the comparison point (starting point) exceeds > bounds (i.e., the [0,n-1] interval) in the first place and that, > instead, the starting point should be fixed. > > This has the welcome side-effect of also fixing the case where the > starting point was n while searching down, which also lead to an > infinite loop. > > OTOH, this code is now essentially all his work. > > Amazingly, nobody seems to have been hit by this for 11 years - or at > the very least nobody bothered to debug and fix this. > > Signed-off-by: Mihai Moldovan > --- Applied to linux-kbuild. Thanks. > v2: swap constant in comparison to right side, as requested by > Randy Dunlap > v3: reimplement as suggested by Masahiro Yamada , > which has the side-effect of also fixing endless looping in the > symmetric down-direction > > scripts/kconfig/nconf.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c > index e0f965529166..af814b39b876 100644 > --- a/scripts/kconfig/nconf.c > +++ b/scripts/kconfig/nconf.c > @@ -504,8 +504,8 @@ static int get_mext_match(const char *match_str, match_f flag) > else if (flag == FIND_NEXT_MATCH_UP) > --match_start; > > + match_start = (match_start + items_num) % items_num; > index = match_start; > - index = (index + items_num) % items_num; > while (true) { > char *str = k_menu_items[index].str; > if (strcasestr(str, match_str) != NULL) > -- > 2.30.1 > -- Best Regards Masahiro Yamada