comparison src/userfunc.c @ 26452:65b4109a4297 v8.2.3756

patch 8.2.3756: might crash when callback is not valid Commit: https://github.com/vim/vim/commit/4dc24eb5adbcc76838fae1e900936dd230209d96 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Tue Dec 7 12:23:57 2021 +0000 patch 8.2.3756: might crash when callback is not valid Problem: might crash when callback is not valid. Solution: Check for valid callback. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/9293)
author Bram Moolenaar <Bram@vim.org>
date Tue, 07 Dec 2021 13:30:05 +0100
parents 568f93dcdc62
children 7821550ba3a8
comparison
equal deleted inserted replaced
26451:27720705109b 26452:65b4109a4297
3144 return callback_depth; 3144 return callback_depth;
3145 } 3145 }
3146 3146
3147 /* 3147 /*
3148 * Invoke call_func() with a callback. 3148 * Invoke call_func() with a callback.
3149 * Returns FAIL if the callback could not be called.
3149 */ 3150 */
3150 int 3151 int
3151 call_callback( 3152 call_callback(
3152 callback_T *callback, 3153 callback_T *callback,
3153 int len, // length of "name" or -1 to use strlen() 3154 int len, // length of "name" or -1 to use strlen()
3157 // PLUS ONE elements! 3158 // PLUS ONE elements!
3158 { 3159 {
3159 funcexe_T funcexe; 3160 funcexe_T funcexe;
3160 int ret; 3161 int ret;
3161 3162
3163 if (callback->cb_name == NULL || *callback->cb_name == NUL)
3164 return FAIL;
3162 CLEAR_FIELD(funcexe); 3165 CLEAR_FIELD(funcexe);
3163 funcexe.evaluate = TRUE; 3166 funcexe.evaluate = TRUE;
3164 funcexe.partial = callback->cb_partial; 3167 funcexe.partial = callback->cb_partial;
3165 ++callback_depth; 3168 ++callback_depth;
3166 ret = call_func(callback->cb_name, len, rettv, argcount, argvars, &funcexe); 3169 ret = call_func(callback->cb_name, len, rettv, argcount, argvars, &funcexe);
3168 return ret; 3171 return ret;
3169 } 3172 }
3170 3173
3171 /* 3174 /*
3172 * call the 'callback' function and return the result as a number. 3175 * call the 'callback' function and return the result as a number.
3173 * Returns -1 when calling the function fails. Uses argv[0] to argv[argc - 1] 3176 * Returns -2 when calling the function fails. Uses argv[0] to argv[argc - 1]
3174 * for the function arguments. argv[argc] should have type VAR_UNKNOWN. 3177 * for the function arguments. argv[argc] should have type VAR_UNKNOWN.
3175 */ 3178 */
3176 varnumber_T 3179 varnumber_T
3177 call_callback_retnr( 3180 call_callback_retnr(
3178 callback_T *callback, 3181 callback_T *callback,
3182 { 3185 {
3183 typval_T rettv; 3186 typval_T rettv;
3184 varnumber_T retval; 3187 varnumber_T retval;
3185 3188
3186 if (call_callback(callback, 0, &rettv, argcount, argvars) == FAIL) 3189 if (call_callback(callback, 0, &rettv, argcount, argvars) == FAIL)
3187 return -1; 3190 return -2;
3188 3191
3189 retval = tv_get_number_chk(&rettv, NULL); 3192 retval = tv_get_number_chk(&rettv, NULL);
3190 clear_tv(&rettv); 3193 clear_tv(&rettv);
3191 return retval; 3194 return retval;
3192 } 3195 }