On So, 25 Sep 2016, vim-dev ML wrote:
> Hi Bram!
>
> On Do, 22 Sep 2016, Bram Moolenaar wrote:
>
> >
> > Christian Brabandt wrote:
> >
> > > This patch fixes it.
> > > ```patch
> > > diff --git a/src/fileio.c b/src/fileio.c
> > > index ea1f338..193e4fd 100644
> > > --- a/src/fileio.c
> > > +++ b/src/fileio.c
> > > @@ -3011,6 +3011,9 @@ check_for_cryptkey(
> > >
> > > /* Remove cryptmethod specific header from the text. */
> > > header_len = crypt_get_header_len(method);
> > > + if (*sizep <= header_len)
> > > + /* buffer can't be encrypted */
> > > + return NULL;
> > > *filesizep += header_len;
> > > *sizep -= header_len;
> > > mch_memmove(ptr, ptr + header_len, (size_t)*sizep);
> > > ```
> >
> > Thanks. Would be good to have a test. Should be possible by writing an
> > encrypted file and then opening it in binary mode.
>
> Updated patch attached.
Sorry, the patch did not survive github. This time really attached to
the vim-dev list.
Best,
Christian
--
Wenn man einen Tausendfüßler erklären lassen würde, nach welchem
Schema er eigentlich gehe, so wird dieser auf der Stelle unfähig sein,
auch nur einen einzelnen Schritt zu machen.
-- Josef Mittendorfer
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
From aabead5922feab118f30e2d80b236da22d4843cd Mon Sep 17 00:00:00 2001
From: Christian Brabandt <[email protected]>
Date: Sun, 25 Sep 2016 20:50:00 +0200
Subject: [PATCH] Add safety check, when trying to read a file, that looks
encrypted
---
src/fileio.c | 3 +++
src/testdir/Make_all.mak | 1 +
src/testdir/test_crypt.vim | 16 ++++++++++++++++
3 files changed, 20 insertions(+)
create mode 100644 src/testdir/test_crypt.vim
diff --git a/src/fileio.c b/src/fileio.c
index ea1f338..5cddca2 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -3011,6 +3011,9 @@ check_for_cryptkey(
/* Remove cryptmethod specific header from the text. */
header_len = crypt_get_header_len(method);
+ if (*sizep <= header_len)
+ /* buffer can't be encrypted */
+ return NULL;
*filesizep += header_len;
*sizep -= header_len;
mch_memmove(ptr, ptr + header_len, (size_t)*sizep);
diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak
index 65ad3ee..999f519 100644
--- a/src/testdir/Make_all.mak
+++ b/src/testdir/Make_all.mak
@@ -149,6 +149,7 @@ NEW_TESTS = test_arglist.res \
test_channel.res \
test_charsearch.res \
test_cmdline.res \
+ test_crypt.res \
test_cscope.res \
test_diffmode.res \
test_digraph.res \
diff --git a/src/testdir/test_crypt.vim b/src/testdir/test_crypt.vim
new file mode 100644
index 0000000..53367b4
--- /dev/null
+++ b/src/testdir/test_crypt.vim
@@ -0,0 +1,16 @@
+" Test for crypt mode
+
+fun! Test_crypted()
+ new
+ call append(0, 'VimCrypt~02!abc')
+ w! Xnon_crypted.txt
+ bw!
+ new
+ f Xnon_crypted.txt
+ set key=key
+ e!
+ call assert_equal('VimCrypt~02!abc', getline(1))
+ set key=
+ bw!
+ call delete('Xnon_crypted.txt')
+endfu
--
2.1.4