1
0
forked from aniani/vim

patch 9.1.1270: missing out-of-memory checks in buffer.c

Problem:  missing out-of-memory checks in buffer.c
Solution: handle out-of-memory situations during allocation
          (John Marriott)

closes: #17031

Signed-off-by: John Marriott <basilisk@internode.on.net>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
John Marriott
2025-04-02 20:32:35 +02:00
committed by Christian Brabandt
parent 8293574c8b
commit 7fb90815a0
2 changed files with 35 additions and 21 deletions

View File

@@ -2926,6 +2926,8 @@ ExpandBufnames(
p = home_replace_save(buf, p); p = home_replace_save(buf, p);
else else
p = vim_strsave(p); p = vim_strsave(p);
if (p == NULL)
return FAIL;
if (!fuzzy) if (!fuzzy)
{ {
@@ -4030,9 +4032,12 @@ maketitle(void)
else else
{ {
p = transstr(gettail(curbuf->b_fname)); p = transstr(gettail(curbuf->b_fname));
if (p != NULL)
{
vim_strncpy(buf, p, SPACE_FOR_FNAME); vim_strncpy(buf, p, SPACE_FOR_FNAME);
vim_free(p); vim_free(p);
} }
}
#ifdef FEAT_TERMINAL #ifdef FEAT_TERMINAL
if (curbuf->b_term == NULL) if (curbuf->b_term == NULL)
@@ -4084,9 +4089,12 @@ maketitle(void)
if (off < SPACE_FOR_DIR) if (off < SPACE_FOR_DIR)
{ {
p = transstr(buf + off); p = transstr(buf + off);
if (p != NULL)
{
vim_strncpy(buf + off, p, (size_t)(SPACE_FOR_DIR - off)); vim_strncpy(buf + off, p, (size_t)(SPACE_FOR_DIR - off));
vim_free(p); vim_free(p);
} }
}
else else
{ {
vim_strncpy(buf + off, (char_u *)"...", vim_strncpy(buf + off, (char_u *)"...",
@@ -4767,6 +4775,9 @@ build_stl_str_hl(
size_t new_fmt_len = parsed_usefmt size_t new_fmt_len = parsed_usefmt
+ str_length + fmt_length + 3; + str_length + fmt_length + 3;
char_u *new_fmt = (char_u *)alloc(new_fmt_len * sizeof(char_u)); char_u *new_fmt = (char_u *)alloc(new_fmt_len * sizeof(char_u));
if (new_fmt != NULL)
{
char_u *new_fmt_p = new_fmt; char_u *new_fmt_p = new_fmt;
new_fmt_p = (char_u *)memcpy(new_fmt_p, usefmt, parsed_usefmt) new_fmt_p = (char_u *)memcpy(new_fmt_p, usefmt, parsed_usefmt)
@@ -4787,6 +4798,7 @@ build_stl_str_hl(
evaldepth++; evaldepth++;
continue; continue;
} }
}
#endif #endif
break; break;
} }

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 */
/**/
1270,
/**/ /**/
1269, 1269,
/**/ /**/