From patchwork Tue Jun 12 19:06:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dirk Gouders X-Patchwork-Id: 10460939 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E07EB601A0 for ; Tue, 12 Jun 2018 19:08:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D161B28912 for ; Tue, 12 Jun 2018 19:08:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C36FB28A04; Tue, 12 Jun 2018 19:08:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=2.0 tests=BAYES_00, DKIM_ADSP_DISCARD, DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0195A28912 for ; Tue, 12 Jun 2018 19:08:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933125AbeFLTIo (ORCPT ); Tue, 12 Jun 2018 15:08:44 -0400 Received: from services.gouders.net ([141.101.32.176]:37470 "EHLO services.gouders.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933313AbeFLTIn (ORCPT ); Tue, 12 Jun 2018 15:08:43 -0400 Received: from lena.gouders.net (ipservice-047-071-023-039.pools.arcor-ip.net [47.71.23.39]) (authenticated bits=0) by services.gouders.net (8.14.8/8.14.8) with ESMTP id w5CJ6AUJ014173 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Tue, 12 Jun 2018 21:06:21 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gouders.net; s=gnet; t=1528830381; bh=q2cIPci0gzMqTke4l/CZlofQ0NBYmisFuu/tWiVH7u0=; h=From:To:Cc:Subject:Date; b=U1rgFEbu1FebTRbQb0IP8r2R9NyJ9/8agczJ0HRPq5i+w/4APIVSMp0q6yeBkDAMK ZfbtDvQ+ZD+io54YxNcvn0z2cT57jtdPMQjM/nNpUVYKYMLfsh4c5dyMBAwIy9FtO7 KRBF7um3nlshuZ3C7zmSdP/GzEKrNri7CWU8ABQ8= From: Dirk Gouders To: Masahiro Yamada , Linux Kbuild mailing list , Randy Dunlap Cc: Dirk Gouders Subject: [PATCH v2] nconf: respect i-search pattern boundaries Date: Tue, 12 Jun 2018 21:06:04 +0200 Message-Id: <20180612190604.4889-1-dirk@gouders.net> X-Mailer: git-send-email 2.16.4 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds boundary checks for nconf's i-search pattern. Further, the pattern buffer is always bzero'ed when '/' is pressed, so the second line in the code below was not needed (and otherwise wouldn't have worked as expected): state->pattern[strlen(state->pattern)] = c; state->pattern[strlen(state->pattern)] = '\0'; Finally, the pattern length was reduced to a length that still seems sufficient but will not fill more than the top line of the screen, thus eliminating special treatment needs on resizes or normal exit of i-search. Signed-off-by: Dirk Gouders --- Changes in v2: Correct S-O-B line, remove double search from subject. --- scripts/kconfig/nconf.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c index 97b78445584b..0e224528aaf9 100644 --- a/scripts/kconfig/nconf.c +++ b/scripts/kconfig/nconf.c @@ -1007,11 +1007,12 @@ static void adj_match_dir(match_f *match_direction) /* else, do no change.. */ } +#define PATTERN_LENGTH 64 struct match_state { int in_search; match_f match_direction; - char pattern[256]; + char pattern[PATTERN_LENGTH]; }; /* Return 0 means I have handled the key. In such a case, ans should hold the @@ -1035,8 +1036,8 @@ static int do_match(int key, struct match_state *state, int *ans) return 1; if (isalnum(c) || isgraph(c) || c == ' ') { - state->pattern[strlen(state->pattern)] = c; - state->pattern[strlen(state->pattern)] = '\0'; + if (strlen(state->pattern) + 1 < PATTERN_LENGTH) + state->pattern[strlen(state->pattern)] = c; adj_match_dir(&state->match_direction); *ans = get_mext_match(state->pattern, state->match_direction); @@ -1049,7 +1050,8 @@ static int do_match(int key, struct match_state *state, int *ans) *ans = get_mext_match(state->pattern, state->match_direction); } else if (key == KEY_BACKSPACE || key == 127) { - state->pattern[strlen(state->pattern)-1] = '\0'; + if (state->pattern[0] != '\0') + state->pattern[strlen(state->pattern)-1] = '\0'; adj_match_dir(&state->match_direction); } else terminate_search = 1;