1fa1ff
To: vim_dev@googlegroups.com
1fa1ff
Subject: Patch 7.4.009
1fa1ff
Fcc: outbox
1fa1ff
From: Bram Moolenaar <Bram@moolenaar.net>
1fa1ff
Mime-Version: 1.0
1fa1ff
Content-Type: text/plain; charset=UTF-8
1fa1ff
Content-Transfer-Encoding: 8bit
1fa1ff
------------
1fa1ff
1fa1ff
Patch 7.4.009
1fa1ff
Problem:    When a file was not decrypted (yet), writing it may destroy the
1fa1ff
	    contents.
1fa1ff
Solution:   Mark the file as readonly until decryption was done. (Christian
1fa1ff
	    Brabandt)
1fa1ff
Files:	    src/fileio.c
1fa1ff
1fa1ff
1fa1ff
*** ../vim-7.4.008/src/fileio.c	2013-08-05 21:58:03.000000000 +0200
1fa1ff
--- src/fileio.c	2013-08-25 17:45:27.000000000 +0200
1fa1ff
***************
1fa1ff
*** 2926,2934 ****
1fa1ff
--- 2926,2939 ----
1fa1ff
      int		*did_ask;	/* flag: whether already asked for key */
1fa1ff
  {
1fa1ff
      int method = crypt_method_from_magic((char *)ptr, *sizep);
1fa1ff
+     int b_p_ro = curbuf->b_p_ro;
1fa1ff
  
1fa1ff
      if (method >= 0)
1fa1ff
      {
1fa1ff
+ 	/* Mark the buffer as read-only until the decryption has taken place.
1fa1ff
+ 	 * Avoids accidentally overwriting the file with garbage. */
1fa1ff
+ 	curbuf->b_p_ro = TRUE;
1fa1ff
+ 
1fa1ff
  	set_crypt_method(curbuf, method);
1fa1ff
  	if (method > 0)
1fa1ff
  	    (void)blowfish_self_test();
1fa1ff
***************
1fa1ff
*** 2977,2982 ****
1fa1ff
--- 2982,2989 ----
1fa1ff
  	    *sizep -= CRYPT_MAGIC_LEN + salt_len + seed_len;
1fa1ff
  	    mch_memmove(ptr, ptr + CRYPT_MAGIC_LEN + salt_len + seed_len,
1fa1ff
  							      (size_t)*sizep);
1fa1ff
+ 	    /* Restore the read-only flag. */
1fa1ff
+ 	    curbuf->b_p_ro = b_p_ro;
1fa1ff
  	}
1fa1ff
      }
1fa1ff
      /* When starting to edit a new file which does not have encryption, clear
1fa1ff
*** ../vim-7.4.008/src/version.c	2013-08-25 17:01:36.000000000 +0200
1fa1ff
--- src/version.c	2013-08-25 17:44:30.000000000 +0200
1fa1ff
***************
1fa1ff
*** 729,730 ****
1fa1ff
--- 729,732 ----
1fa1ff
  {   /* Add new patch number below this line */
1fa1ff
+ /**/
1fa1ff
+     9,
1fa1ff
  /**/
1fa1ff
1fa1ff
-- 
1fa1ff
I have a watch cat! Just break in and she'll watch.
1fa1ff
1fa1ff
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
1fa1ff
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
1fa1ff
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
1fa1ff
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///