From 7a3fef9e348be541c585fd3544c912950387641f Mon Sep 17 00:00:00 2001 From: Thomas Vigouroux Date: Sat, 19 Aug 2023 02:19:36 +0200 Subject: refactor(tui): check for out of bound access after snprintf (#24751) Counterintuitively, snprintf returns the number of characters it _should have written_ if it had not encoutered the length bound, thus leading to a potential buffer overflow. Co-authored-by: zeertzjq --- src/nvim/tui/input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index 7af28561c2..c55cb44560 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -297,10 +297,10 @@ static void forward_simple_utf8(TermInput *input, TermKeyKey *key) } else { buf[len++] = *ptr; } + assert(len < sizeof(buf)); ptr++; } - assert(len < sizeof(buf)); tinput_enqueue(input, buf, len); } -- cgit