0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 9.0.1995: Invalid memory access with empty 'foldexpr'

Problem:  Invalid memory access when 'foldexpr' returns empty string.
Solution: Check for NUL.

closes: #13293

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
This commit is contained in:
zeertzjq
2023-10-06 19:16:36 +02:00
committed by Christian Brabandt
parent ac9c6d5c78
commit a991ce9c08
3 changed files with 12 additions and 1 deletions

View File

@@ -968,7 +968,7 @@ eval_foldexpr(win_T *wp, int *cp)
// If the result is a string, check if there is a non-digit before // If the result is a string, check if there is a non-digit before
// the number. // the number.
s = tv.vval.v_string; s = tv.vval.v_string;
if (!VIM_ISDIGIT(*s) && *s != '-') if (*s != NUL && !VIM_ISDIGIT(*s) && *s != '-')
*cp = *s++; *cp = *s++;
retval = atol((char *)s); retval = atol((char *)s);
} }

View File

@@ -1769,4 +1769,13 @@ func Test_foldcolumn_linebreak_control_char()
bwipe! bwipe!
endfunc endfunc
" This used to cause invalid memory access
func Test_foldexpr_return_empty_string()
new
setlocal foldexpr='' foldmethod=expr
redraw
bwipe!
endfunc

View File

@@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1995,
/**/ /**/
1994, 1994,
/**/ /**/