summaryrefslogtreecommitdiffstats
path: root/src/fileio.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2013-08-25 17:46:08 +0200
committerBram Moolenaar <Bram@vim.org>2013-08-25 17:46:08 +0200
commitcf81aefd9c33e2619965ce9854c79105dc7b8bea (patch)
tree462ec2aceebe610b49294d98489ba4c0ed3a3611 /src/fileio.c
parent41f1205fef7eb24656abb3eeb1dea9ff5cdf1b62 (diff)
updated for version 7.4.009v7.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)
Diffstat (limited to 'src/fileio.c')
-rw-r--r--src/fileio.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/fileio.c b/src/fileio.c
index b48a83a3cd..010d933a12 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -2926,9 +2926,14 @@ check_for_cryptkey(cryptkey, ptr, sizep, filesizep, newfile, fname, did_ask)
int *did_ask; /* flag: whether already asked for key */
{
int method = crypt_method_from_magic((char *)ptr, *sizep);
+ int b_p_ro = curbuf->b_p_ro;
if (method >= 0)
{
+ /* Mark the buffer as read-only until the decryption has taken place.
+ * Avoids accidentally overwriting the file with garbage. */
+ curbuf->b_p_ro = TRUE;
+
set_crypt_method(curbuf, method);
if (method > 0)
(void)blowfish_self_test();
@@ -2977,6 +2982,8 @@ check_for_cryptkey(cryptkey, ptr, sizep, filesizep, newfile, fname, did_ask)
*sizep -= CRYPT_MAGIC_LEN + salt_len + seed_len;
mch_memmove(ptr, ptr + CRYPT_MAGIC_LEN + salt_len + seed_len,
(size_t)*sizep);
+ /* Restore the read-only flag. */
+ curbuf->b_p_ro = b_p_ro;
}
}
/* When starting to edit a new file which does not have encryption, clear