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