Skip to content

Commit 680e015

Browse files
committed
patch 8.0.0010
Problem: Crash when editing file that starts with crypt yeader. (igor2x) Solution: Check for length of text. (Christian Brabandt) Add a test.
1 parent 3f1c15b commit 680e015

5 files changed

Lines changed: 49 additions & 0 deletions

File tree

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,6 +2066,7 @@ test_arglist \
20662066
test_channel \
20672067
test_charsearch \
20682068
test_cmdline \
2069+
test_crypt \
20692070
test_cscope \
20702071
test_cursor_func \
20712072
test_delete \

src/fileio.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3011,6 +3011,9 @@ check_for_cryptkey(
30113011

30123012
/* Remove cryptmethod specific header from the text. */
30133013
header_len = crypt_get_header_len(method);
3014+
if (*sizep <= header_len)
3015+
/* invalid header, buffer can't be encrypted */
3016+
return NULL;
30143017
*filesizep += header_len;
30153018
*sizep -= header_len;
30163019
mch_memmove(ptr, ptr + header_len, (size_t)*sizep);

src/testdir/Make_all.mak

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ NEW_TESTS = test_arglist.res \
149149
test_channel.res \
150150
test_charsearch.res \
151151
test_cmdline.res \
152+
test_crypt.res \
152153
test_cscope.res \
153154
test_diffmode.res \
154155
test_digraph.res \

src/testdir/test_crypt.vim

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
" Tests for encryption.
2+
" TODO: include tests from test71.
3+
4+
func Common_head_only(text)
5+
" This was crashing Vim
6+
split Xtest.txt
7+
call setline(1, a:text)
8+
wq
9+
call feedkeys(":split Xtest.txt\<CR>foobar\<CR>", "tx")
10+
call delete('Xtest.txt')
11+
call assert_match('VimCrypt', getline(1))
12+
bwipe!
13+
endfunc
14+
15+
func Test_head_only_2()
16+
call Common_head_only('VimCrypt~02!abc')
17+
endfunc
18+
19+
func Test_head_only_3()
20+
call Common_head_only('VimCrypt~03!abc')
21+
endfunc
22+
" Tests for encryption.
23+
" TODO: include tests from test71.
24+
25+
func Common_head_only(text)
26+
" This was crashing Vim
27+
split Xtest.txt
28+
call setline(1, a:text)
29+
wq
30+
call feedkeys(":split Xtest.txt\<CR>foobar\<CR>", "tx")
31+
call delete('Xtest.txt')
32+
call assert_match('VimCrypt', getline(1))
33+
bwipe!
34+
endfunc
35+
36+
func Test_head_only_2()
37+
call Common_head_only('VimCrypt~02!abc')
38+
endfunc
39+
40+
func Test_head_only_3()
41+
call Common_head_only('VimCrypt~03!abc')
42+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
10,
767769
/**/
768770
9,
769771
/**/

0 commit comments

Comments
 (0)