1 Star 0 Fork 52

杨超豪/vim

forked from src-openEuler/vim 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-CVE-2023-0054.patch 1.65 KB
一键复制 编辑 原始数据 按行查看 历史
From 3ac1d97a1d9353490493d30088256360435f7731 Mon Sep 17 00:00:00 2001
From: Bram Moolenaar <Bram@vim.org>
Date: Wed, 4 Jan 2023 17:17:54 +0000
Subject: [PATCH] patch 9.0.1145: invalid memory access with recursive
substitute expression
Problem: Invalid memory access with recursive substitute expression.
Solution: Check the return value of vim_regsub().
---
src/eval.c | 5 +++++
src/testdir/test_substitute.vim | 16 ++++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/src/eval.c b/src/eval.c
index 2fbd867ab..9ca805061 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -6969,6 +6969,11 @@ do_string_sub(
* - The text after the match.
*/
sublen = vim_regsub(&regmatch, sub, expr, tail, 0, REGSUB_MAGIC);
+ if (sublen <= 0)
+ {
+ ga_clear(&ga);
+ break;
+ }
if (ga_grow(&ga, (int)((end - tail) + sublen -
(regmatch.endp[0] - regmatch.startp[0]))) == FAIL)
{
diff --git a/src/testdir/test_substitute.vim b/src/testdir/test_substitute.vim
index 251322337..4268aab03 100644
--- a/src/testdir/test_substitute.vim
+++ b/src/testdir/test_substitute.vim
@@ -1095,6 +1095,22 @@ func Test_sub_expr_goto_other_file()
bwipe!
endfunc
+func Test_recursive_expr_substitute()
+ " this was reading invalid memory
+ let lines =<< trim END
+ func Repl(g, n)
+ s
+ r%:s000
+ endfunc
+ next 0
+ let caught = 0
+ s/\%')/\=Repl(0, 0)
+ qall!
+ END
+ call writefile(lines, 'XexprSubst', 'D')
+ call RunVim([], [], '--clean -S XexprSubst')
+endfunc
+
" Test for the 2-letter and 3-letter :substitute commands
func Test_substitute_short_cmd()
new
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yang-chaohao/vim.git
git@gitee.com:yang-chaohao/vim.git
yang-chaohao
vim
vim
master

搜索帮助