changeset 30001:6c1a9d7a931f v9.0.0338

patch 9.0.0338: return value of list_append_list() not always checked Commit: https://github.com/vim/vim/commit/9ba6194d4cba60fec4ed10c33d2d4fbe6e38c696 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Aug 31 11:25:06 2022 +0100 patch 9.0.0338: return value of list_append_list() not always checked Problem: Return value of list_append_list() not always checked. Solution: Check return value and handle failure.
author Bram Moolenaar <Bram@vim.org>
date Wed, 31 Aug 2022 12:30:06 +0200
parents 3f18d0ae046b
children b3fd1aacd62a
files src/evalfunc.c src/evalwindow.c src/list.c src/search.c src/version.c
diffstat 5 files changed, 46 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -4811,9 +4811,12 @@ f_getchangelist(typval_T *argvars, typva
     l = list_alloc();
     if (l == NULL)
 	return;
-
     if (list_append_list(rettv->vval.v_list, l) == FAIL)
-	return;
+    {
+	vim_free(l);
+	return;
+    }
+
     /*
      * The current window change list index tracks only the position for the
      * current buffer. For other buffers use the stored index for the current
@@ -5045,9 +5048,12 @@ f_getjumplist(typval_T *argvars, typval_
     l = list_alloc();
     if (l == NULL)
 	return;
-
     if (list_append_list(rettv->vval.v_list, l) == FAIL)
-	return;
+    {
+	vim_free(l);
+	return;
+    }
+
     list_append_number(rettv->vval.v_list, (varnumber_T)wp->w_jumplistidx);
 
     for (i = 0; i < wp->w_jumplistlen; ++i)
--- a/src/evalwindow.c
+++ b/src/evalwindow.c
@@ -261,7 +261,7 @@ find_tabwin(
 }
 
 /*
- * Get the layout of the given tab page for winlayout().
+ * Get the layout of the given tab page for winlayout() and add it to "l".
  */
     static void
 get_framelayout(frame_T *fr, list_T *l, int outer)
@@ -281,7 +281,11 @@ get_framelayout(frame_T *fr, list_T *l, 
 	fr_list = list_alloc();
 	if (fr_list == NULL)
 	    return;
-	list_append_list(l, fr_list);
+	if (list_append_list(l, fr_list) == FAIL)
+	{
+	    vim_free(fr_list);
+	    return;
+	}
     }
 
     if (fr->fr_layout == FR_LEAF)
@@ -300,7 +304,12 @@ get_framelayout(frame_T *fr, list_T *l, 
 	win_list = list_alloc();
 	if (win_list == NULL)
 	    return;
-	list_append_list(fr_list, win_list);
+	if (list_append_list(fr_list, win_list) == FAIL)
+	{
+	    vim_free(win_list);
+	    return;
+	}
+
 	child = fr->fr_child;
 	while (child != NULL)
 	{
--- a/src/list.c
+++ b/src/list.c
@@ -1076,8 +1076,12 @@ list2items(typval_T *argvars, typval_T *
 
 	if (l2 == NULL)
 	    break;
-	if (list_append_list(rettv->vval.v_list, l2) == FAIL
-		|| list_append_number(l2, idx) == FAIL
+	if (list_append_list(rettv->vval.v_list, l2) == FAIL)
+	{
+	    vim_free(l2);
+	    break;
+	}
+	if (list_append_number(l2, idx) == FAIL
 		|| list_append_tv(l2, &li->li_tv) == FAIL)
 	    break;
     }
@@ -1108,8 +1112,12 @@ string2items(typval_T *argvars, typval_T
 	l2 = list_alloc();
 	if (l2 == NULL)
 	    break;
-	if (list_append_list(rettv->vval.v_list, l2) == FAIL
-		|| list_append_number(l2, idx) == FAIL
+	if (list_append_list(rettv->vval.v_list, l2) == FAIL)
+	{
+	    vim_free(l2);
+	    break;
+	}
+	if (list_append_number(l2, idx) == FAIL
 		|| list_append_string(l2, p, len) == FAIL)
 	    break;
 	p += len;
--- a/src/search.c
+++ b/src/search.c
@@ -4748,8 +4748,7 @@ fuzzy_match_in_list(
 		if (items[i].score == SCORE_NONE)
 		    break;
 		if (items[i].lmatchpos != NULL
-			&& list_append_list(retlist, items[i].lmatchpos)
-								== FAIL)
+		      && list_append_list(retlist, items[i].lmatchpos) == FAIL)
 		    goto done;
 	    }
 
@@ -4869,17 +4868,26 @@ do_fuzzymatch(typval_T *argvars, typval_
 	if (l == NULL)
 	    goto done;
 	if (list_append_list(rettv->vval.v_list, l) == FAIL)
+	{
+	    vim_free(l);
 	    goto done;
+	}
 	l = list_alloc();
 	if (l == NULL)
 	    goto done;
 	if (list_append_list(rettv->vval.v_list, l) == FAIL)
+	{
+	    vim_free(l);
 	    goto done;
+	}
 	l = list_alloc();
 	if (l == NULL)
 	    goto done;
 	if (list_append_list(rettv->vval.v_list, l) == FAIL)
+	{
+	    vim_free(l);
 	    goto done;
+	}
     }
 
     fuzzy_match_in_list(argvars[0].vval.v_list, tv_get_string(&argvars[1]),
--- a/src/version.c
+++ b/src/version.c
@@ -708,6 +708,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    338,
+/**/
     337,
 /**/
     336,