fzy

terminal fuzzy finder picker

git clone https://9o.is/git/fzy.git

commit 3f66ada7bc512febfa102f8ba7cf0b5c03f483cf
parent adb495dbe19bd0a88598adfdf387ed386ea3e1b8
Author: John Hawthorn <john.hawthorn@gmail.com>
Date:   Sun,  3 Aug 2014 22:05:37 -0700

Fix possible overflow on long search string

Diffstat:
Mfzy.c | 12+++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/fzy.c b/fzy.c @@ -84,8 +84,9 @@ void run_search(char *needle){ #define NUMLINES 10 +#define SEARCH_SIZE_MAX 4096 int search_size; -char search[4096] = {0}; +char search[SEARCH_SIZE_MAX + 1] = {0}; void clear(tty_t *tty){ fprintf(tty->fout, "%c%c0G", 0x1b, '['); @@ -156,10 +157,11 @@ void run(tty_t *tty){ draw(tty); ch = tty_getchar(tty); if(isprint(ch)){ - /* FIXME: overflow */ - search[search_size++] = ch; - search[search_size] = '\0'; - run_search(search); + if(search_size < SEARCH_SIZE_MAX){ + search[search_size++] = ch; + search[search_size] = '\0'; + run_search(search); + } }else if(ch == 127 || ch == 8){ /* DEL || backspace */ if(search_size) search[--search_size] = '\0';