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