vim-patch:9.2.0271: buffer underflow in vim_fgets() (#38575)

Problem:  buffer underflow in vim_fgets()
Solution: Ensure size is always greater than 1
          (Koda Reef)

3c0f8000e1

This currently never happens in Nvim.

Co-authored-by: Koda Reef <kodareef5@gmail.com>
This commit is contained in:
zeertzjq
2026-03-30 07:20:21 +08:00
committed by GitHub
parent 844f2d2e13
commit 33e17d66c6

View File

@@ -2498,7 +2498,14 @@ bool vim_fgets(char *buf, int size, FILE *fp)
{
char *retval;
assert(size > 0);
// safety check
if (size < 2) {
if (size == 1) {
buf[0] = NUL;
}
return true;
}
buf[size - 2] = NUL;
do {