astepano / rpms / vim

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