From patchwork Tue Jun 12 12:04:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dirk Gouders X-Patchwork-Id: 10460113 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 E6A77602A0 for ; Tue, 12 Jun 2018 12:05:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC6452870D for ; Tue, 12 Jun 2018 12:05:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D123428714; Tue, 12 Jun 2018 12:05:13 +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 25E482870D for ; Tue, 12 Jun 2018 12:05:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933378AbeFLMFJ (ORCPT ); Tue, 12 Jun 2018 08:05:09 -0400 Received: from services.gouders.net ([141.101.32.176]:41434 "EHLO services.gouders.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933350AbeFLMFH (ORCPT ); Tue, 12 Jun 2018 08:05:07 -0400 Received: from lena.gouders.net ([193.175.198.193]) (authenticated bits=0) by services.gouders.net (8.14.8/8.14.8) with ESMTP id w5CC4qcT008095 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Tue, 12 Jun 2018 14:05:03 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gouders.net; s=gnet; t=1528805103; bh=eevTv5tsO/kTFYUoLBdW12ywLyqI5N8O/QrtlRtq6Cs=; h=From:To:Cc:Subject:Date; b=uwfCCBtAPZ2eMdnbm9/fh17RW3s/0L0MIJN/15ZsiJZDQX7HvsPCY6fCILEJJRuZy uyADzQ+qXG0XOF1o9FFGqOco9A0x78dM/KxZgAEPOyVU9fEEsG3sHabhG/uT8zEUPu 7ctJI9iGedtwSZuaFBxVfuR2YaJwupcgEGEZbDdY= From: Dirk Gouders To: Masahiro Yamada , Linux Kbuild mailing list Cc: Dirk Gouders , Dirk@services.gouders.net Subject: [PATCH] nconf: respect i-search search pattern boundaries Date: Tue, 12 Jun 2018 14:04:41 +0200 Message-Id: <20180612120441.22325-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 --- 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;