From f575b714499bf74ca99597fc5d115395e14dfcd1 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 29 Aug 2019 20:35:35 -0400 Subject: vim-patch:8.1.1938: may crash when out of memory Problem: May crash when out of memory. Solution: Initialize v_type to VAR_UNKNOWN. (Dominique Pelle, closes vim/vim#4871) https://github.com/vim/vim/commit/c507a2d164cfa3dcf31a7ba9dad6663a17243bb4 --- src/nvim/eval.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index d883b53ed2..9f1f564a9b 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6437,6 +6437,10 @@ call_func( typval_T argv[MAX_FUNC_ARGS + 1]; // used when "partial" is not NULL int argv_clear = 0; + // Initialize rettv so that it is safe for caller to invoke clear_tv(rettv) + // even when call_func() returns FAIL. + rettv->v_type = VAR_UNKNOWN; + // Make a copy of the name, if it comes from a funcref variable it could // be changed or deleted in the called function. name = vim_strnsave(funcname, len); @@ -6465,13 +6469,7 @@ call_func( } } - - // Execute the function if executing and no errors were detected. - if (!evaluate) { - // Not evaluating, which means the return value is unknown. This - // matters for giving error messages. - rettv->v_type = VAR_UNKNOWN; - } else if (error == ERROR_NONE) { + if (error == ERROR_NONE && evaluate) { char_u *rfname = fname; /* Ignore "g:" before a function name. */ -- cgit From 97c1775646b87e7127a93daa13aab3d09e8e4b88 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 29 Aug 2019 23:25:16 -0400 Subject: vim-patch:8.1.0233: "safe" argument of call_vim_function() is always FALSE Problem: "safe" argument of call_vim_function() is always FALSE. Solution: Remove the argument. https://github.com/vim/vim/commit/ded27a1febda3db7447958b60a7d791af514d124 --- src/nvim/eval.c | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 9f1f564a9b..12c53fa804 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -1307,27 +1307,17 @@ int call_vim_function( const char_u *func, int argc, typval_T *argv, - typval_T *rettv, - bool safe // use the sandbox + typval_T *rettv ) + FUNC_ATTR_NONNULL_ALL { int doesrange; - void *save_funccalp = NULL; int ret; - if (safe) { - save_funccalp = save_funccal(); - ++sandbox; - } - rettv->v_type = VAR_UNKNOWN; // tv_clear() uses this. ret = call_func(func, (int)STRLEN(func), rettv, argc, argv, NULL, curwin->w_cursor.lnum, curwin->w_cursor.lnum, &doesrange, true, NULL, NULL); - if (safe) { - --sandbox; - restore_funccal(save_funccalp); - } if (ret == FAIL) { tv_clear(rettv); @@ -1340,16 +1330,16 @@ int call_vim_function( /// @param[in] func Function name. /// @param[in] argc Number of arguments. /// @param[in] argv Array with typval_T arguments. -/// @param[in] safe Use with sandbox. /// /// @return -1 when calling function fails, result of function otherwise. -varnumber_T call_func_retnr(char_u *func, int argc, - typval_T *argv, int safe) +varnumber_T call_func_retnr(const char_u *func, int argc, + typval_T *argv) + FUNC_ATTR_NONNULL_ALL { typval_T rettv; varnumber_T retval; - if (call_vim_function(func, argc, argv, &rettv, safe) == FAIL) { + if (call_vim_function(func, argc, argv, &rettv) == FAIL) { return -1; } retval = tv_get_number_chk(&rettv, NULL); @@ -1361,18 +1351,16 @@ varnumber_T call_func_retnr(char_u *func, int argc, /// @param[in] func Function name. /// @param[in] argc Number of arguments. /// @param[in] argv Array with typval_T arguments. -/// @param[in] safe Use the sandbox. /// /// @return [allocated] NULL when calling function fails, allocated string /// otherwise. char *call_func_retstr(const char *const func, int argc, - typval_T *argv, - bool safe) - FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_MALLOC + typval_T *argv) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_MALLOC { typval_T rettv; // All arguments are passed as strings, no conversion to number. - if (call_vim_function((const char_u *)func, argc, argv, &rettv, safe) + if (call_vim_function((const char_u *)func, argc, argv, &rettv) == FAIL) { return NULL; } @@ -1386,17 +1374,16 @@ char *call_func_retstr(const char *const func, int argc, /// @param[in] func Function name. /// @param[in] argc Number of arguments. /// @param[in] argv Array with typval_T arguments. -/// @param[in] safe Use the sandbox. /// /// @return [allocated] NULL when calling function fails or return tv is not a /// List, allocated List otherwise. -void *call_func_retlist(char_u *func, int argc, typval_T *argv, - bool safe) +void *call_func_retlist(const char_u *func, int argc, typval_T *argv) + FUNC_ATTR_NONNULL_ALL { typval_T rettv; // All arguments are passed as strings, no conversion to number. - if (call_vim_function(func, argc, argv, &rettv, safe) == FAIL) { + if (call_vim_function(func, argc, argv, &rettv) == FAIL) { return NULL; } -- cgit