Skip to content

Commit cbeea0f

Browse files
committed
updated for version 7.4.009
Problem: When a file was not decrypted (yet), writing it may destroy the contents. Solution: Mark the file as readonly until decryption was done. (Christian Brabandt)
1 parent 335193b commit cbeea0f

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/fileio.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,9 +2926,14 @@ check_for_cryptkey(cryptkey, ptr, sizep, filesizep, newfile, fname, did_ask)
29262926
int *did_ask; /* flag: whether already asked for key */
29272927
{
29282928
int method = crypt_method_from_magic((char *)ptr, *sizep);
2929+
int b_p_ro = curbuf->b_p_ro;
29292930

29302931
if (method >= 0)
29312932
{
2933+
/* Mark the buffer as read-only until the decryption has taken place.
2934+
* Avoids accidentally overwriting the file with garbage. */
2935+
curbuf->b_p_ro = TRUE;
2936+
29322937
set_crypt_method(curbuf, method);
29332938
if (method > 0)
29342939
(void)blowfish_self_test();
@@ -2977,6 +2982,8 @@ check_for_cryptkey(cryptkey, ptr, sizep, filesizep, newfile, fname, did_ask)
29772982
*sizep -= CRYPT_MAGIC_LEN + salt_len + seed_len;
29782983
mch_memmove(ptr, ptr + CRYPT_MAGIC_LEN + salt_len + seed_len,
29792984
(size_t)*sizep);
2985+
/* Restore the read-only flag. */
2986+
curbuf->b_p_ro = b_p_ro;
29802987
}
29812988
}
29822989
/* When starting to edit a new file which does not have encryption, clear

src/version.c

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

728728
static int included_patches[] =
729729
{ /* Add new patch number below this line */
730+
/**/
731+
9,
730732
/**/
731733
8,
732734
/**/

0 commit comments

Comments
 (0)