Mercurial > vim
comparison src/ex_cmds.c @ 28909:1890fa76a634 v8.2.4977
patch 8.2.4977: memory access error when substitute expression changes window
Commit: https://github.com/vim/vim/commit/e2bd8600b873d2cd1f9d667c28cba8b1dba18839
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed May 18 13:11:57 2022 +0100
patch 8.2.4977: memory access error when substitute expression changes window
Problem: Memory access error when substitute expression changes window.
Solution: Disallow changing window in substitute expression.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 18 May 2022 14:15:02 +0200 |
parents | d0241e74bfdb |
children | 45c182c4f7e9 |
comparison
equal
deleted
inserted
replaced
28908:89001c986b21 | 28909:1890fa76a634 |
---|---|
4410 sandbox++; | 4410 sandbox++; |
4411 } | 4411 } |
4412 // Save flags for recursion. They can change for e.g. | 4412 // Save flags for recursion. They can change for e.g. |
4413 // :s/^/\=execute("s#^##gn") | 4413 // :s/^/\=execute("s#^##gn") |
4414 subflags_save = subflags; | 4414 subflags_save = subflags; |
4415 | |
4416 // Disallow changing text or switching window in an expression. | |
4417 ++textwinlock; | |
4415 #endif | 4418 #endif |
4416 // get length of substitution part | 4419 // get length of substitution part |
4417 sublen = vim_regsub_multi(®match, | 4420 sublen = vim_regsub_multi(®match, |
4418 sub_firstlnum - regmatch.startpos[0].lnum, | 4421 sub_firstlnum - regmatch.startpos[0].lnum, |
4419 sub, sub_firstline, FALSE, magic_isset(), TRUE); | 4422 sub, sub_firstline, FALSE, magic_isset(), TRUE); |
4420 #ifdef FEAT_EVAL | 4423 #ifdef FEAT_EVAL |
4424 --textwinlock; | |
4425 | |
4421 // If getting the substitute string caused an error, don't do | 4426 // If getting the substitute string caused an error, don't do |
4422 // the replacement. | 4427 // the replacement. |
4423 // Don't keep flags set by a recursive call. | 4428 // Don't keep flags set by a recursive call. |
4424 subflags = subflags_save; | 4429 subflags = subflags_save; |
4425 if (aborting() || subflags.do_count) | 4430 if (aborting() || subflags.do_count) |
4516 * copy the text up to the part that matched | 4521 * copy the text up to the part that matched |
4517 */ | 4522 */ |
4518 mch_memmove(new_end, sub_firstline + copycol, (size_t)copy_len); | 4523 mch_memmove(new_end, sub_firstline + copycol, (size_t)copy_len); |
4519 new_end += copy_len; | 4524 new_end += copy_len; |
4520 | 4525 |
4526 #ifdef FEAT_EVAL | |
4527 ++textwinlock; | |
4528 #endif | |
4521 (void)vim_regsub_multi(®match, | 4529 (void)vim_regsub_multi(®match, |
4522 sub_firstlnum - regmatch.startpos[0].lnum, | 4530 sub_firstlnum - regmatch.startpos[0].lnum, |
4523 sub, new_end, TRUE, magic_isset(), TRUE); | 4531 sub, new_end, TRUE, magic_isset(), TRUE); |
4532 #ifdef FEAT_EVAL | |
4533 --textwinlock; | |
4534 #endif | |
4524 sub_nsubs++; | 4535 sub_nsubs++; |
4525 did_sub = TRUE; | 4536 did_sub = TRUE; |
4526 | 4537 |
4527 // Move the cursor to the start of the line, to avoid that it | 4538 // Move the cursor to the start of the line, to avoid that it |
4528 // is beyond the end of the line after the substitution. | 4539 // is beyond the end of the line after the substitution. |