summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Brabandt <cb@256bit.org>2023-11-14 20:45:48 +0100
committerChristian Brabandt <cb@256bit.org>2023-11-16 22:04:37 +0100
commitac63787734fda2e294e477af52b3bd601517fa78 (patch)
tree79a2df1e1b876a0920d47585343519aa4f8e3b9b /src
parentcb0b99f0672d8446585d26e998343dceca17d1ce (diff)
patch 9.0.2108: [security]: overflow with count for :s commandv9.0.2108
Problem: [security]: overflow with count for :s command Solution: Abort the :s command if the count is too large If the count after the :s command is larger than what fits into a (signed) long variable, abort with e_value_too_large. Adds a test with INT_MAX as count and verify it correctly fails. It seems the return value on Windows using mingw compiler wraps around, so the initial test using :s/./b/9999999999999999999999999990 doesn't fail there, since the count is wrapping around several times and finally is no longer larger than 2147483647. So let's just use 2147483647 in the test, which hopefully will always cause a failure Signed-off-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'src')
-rw-r--r--src/ex_cmds.c7
-rw-r--r--src/testdir/test_substitute.vim1
-rw-r--r--src/version.c2
3 files changed, 10 insertions, 0 deletions
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index 3544092d65..c5f912e7ee 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -3993,6 +3993,13 @@ ex_substitute(exarg_T *eap)
emsg(_(e_positive_count_required));
return;
}
+ else if (i >= INT_MAX)
+ {
+ char buf[20];
+ vim_snprintf(buf, sizeof(buf), "%ld", i);
+ semsg(_(e_val_too_large), buf);
+ return;
+ }
eap->line1 = eap->line2;
eap->line2 += i - 1;
if (eap->line2 > curbuf->b_ml.ml_line_count)
diff --git a/src/testdir/test_substitute.vim b/src/testdir/test_substitute.vim
index b99d0e0058..3ed159799f 100644
--- a/src/testdir/test_substitute.vim
+++ b/src/testdir/test_substitute.vim
@@ -206,6 +206,7 @@ func Test_substitute_count()
call assert_equal(['foo foo', 'foo foo', 'foo foo', 'bar foo', 'bar foo'],
\ getline(1, '$'))
+ call assert_fails('s/./b/2147483647', 'E1510:')
bwipe!
endfunc
diff --git a/src/version.c b/src/version.c
index 684f3acf4c..16db8f2312 100644
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2108,
+/**/
2107,
/**/
2106,