All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dirk Gouders <dirk@gouders.net>
To: Masahiro Yamada <yamada.masahiro@socionext.com>,
	Linux Kbuild mailing list <linux-kbuild@vger.kernel.org>
Cc: Dirk Gouders <dirk@gouders.net>, Dirk@services.gouders.net
Subject: [PATCH] nconf: respect i-search search pattern boundaries
Date: Tue, 12 Jun 2018 14:04:41 +0200	[thread overview]
Message-ID: <20180612120441.22325-1-dirk@gouders.net> (raw)

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;
-- 
2.16.4


             reply	other threads:[~2018-06-12 12:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-12 12:04 Dirk Gouders [this message]
2018-06-12 16:19 ` [PATCH] nconf: respect i-search search pattern boundaries Randy Dunlap
2018-06-12 19:01   ` Dirk Gouders

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180612120441.22325-1-dirk@gouders.net \
    --to=dirk@gouders.net \
    --cc=Dirk@services.gouders.net \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=yamada.masahiro@socionext.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.