comparison src/userfunc.c @ 33915:a49ae967e9ed v9.0.2158

patch 9.0.2158: [security]: use-after-free in check_argument_type Commit: https://github.com/vim/vim/commit/0f28791b215bd4c22ed580839409c2f7d39d8140 Author: Christian Brabandt <cb@256bit.org> Date: Mon Dec 11 17:53:25 2023 +0100 patch 9.0.2158: [security]: use-after-free in check_argument_type Problem: [security]: use-after-free in check_argument_type Solution: Reset function type pointer when freeing the function type list function pointer fp->uf_func_type may point to the same memory, that was allocated for fp->uf_type_list. However, when cleaning up a function definition (e.g. because it was invalid), fp->uf_type_list will be freed, but fp->uf_func_type may still point to the same (now) invalid memory address. So when freeing the fp->uf_type_list, check if fp->func_type points to any of those types and if it does, reset the fp->uf_func_type pointer to the t_func_any (default) type pointer closes: #13652 Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Mon, 11 Dec 2023 18:00:03 +0100
parents 966a1af141b0
children bdd408288d95
comparison
equal deleted inserted replaced
33914:966a1af141b0 33915:a49ae967e9ed
2531 ga_clear_strings(&(fp->uf_def_args)); 2531 ga_clear_strings(&(fp->uf_def_args));
2532 ga_clear_strings(&(fp->uf_lines)); 2532 ga_clear_strings(&(fp->uf_lines));
2533 VIM_CLEAR(fp->uf_arg_types); 2533 VIM_CLEAR(fp->uf_arg_types);
2534 VIM_CLEAR(fp->uf_block_ids); 2534 VIM_CLEAR(fp->uf_block_ids);
2535 VIM_CLEAR(fp->uf_va_name); 2535 VIM_CLEAR(fp->uf_va_name);
2536 clear_type_list(&fp->uf_type_list); 2536 clear_func_type_list(&fp->uf_type_list, &fp->uf_func_type);
2537 2537
2538 // Increment the refcount of this function to avoid it being freed 2538 // Increment the refcount of this function to avoid it being freed
2539 // recursively when the partial is freed. 2539 // recursively when the partial is freed.
2540 fp->uf_refcount += 3; 2540 fp->uf_refcount += 3;
2541 partial_unref(fp->uf_partial); 2541 partial_unref(fp->uf_partial);
5433 ga_clear_strings(&newlines); 5433 ga_clear_strings(&newlines);
5434 if (fp != NULL) 5434 if (fp != NULL)
5435 { 5435 {
5436 VIM_CLEAR(fp->uf_arg_types); 5436 VIM_CLEAR(fp->uf_arg_types);
5437 VIM_CLEAR(fp->uf_va_name); 5437 VIM_CLEAR(fp->uf_va_name);
5438 clear_type_list(&fp->uf_type_list); 5438 clear_func_type_list(&fp->uf_type_list, &fp->uf_func_type);
5439 } 5439 }
5440 if (free_fp) 5440 if (free_fp)
5441 VIM_CLEAR(fp); 5441 VIM_CLEAR(fp);
5442 ret_free: 5442 ret_free:
5443 ga_clear_strings(&argtypes); 5443 ga_clear_strings(&argtypes);