Blame SOURCES/7.4.403

22c937
To: vim_dev@googlegroups.com
22c937
Subject: Patch 7.4.403
22c937
Fcc: outbox
22c937
From: Bram Moolenaar <Bram@moolenaar.net>
22c937
Mime-Version: 1.0
22c937
Content-Type: text/plain; charset=UTF-8
22c937
Content-Transfer-Encoding: 8bit
22c937
------------
22c937
22c937
Patch 7.4.403
22c937
Problem:    Valgrind reports errors when running test 72. (Dominique Pelle)
22c937
Solution:   Reset the local 'cryptmethod' option before storing the seed.
22c937
	    Set the seed in the memfile even when there is no block0 yet.
22c937
Files:	    src/fileio.c, src/option.c, src/memline.c
22c937
22c937
22c937
*** ../vim-7.4.402/src/fileio.c	2014-08-10 13:34:59.056785459 +0200
22c937
--- src/fileio.c	2014-08-13 21:27:51.452857400 +0200
22c937
***************
22c937
*** 2944,2949 ****
22c937
--- 2944,2950 ----
22c937
  	 * Avoids accidentally overwriting the file with garbage. */
22c937
  	curbuf->b_p_ro = TRUE;
22c937
  
22c937
+ 	/* Set the cryptmethod local to the buffer. */
22c937
  	crypt_set_cm_option(curbuf, method);
22c937
  	if (cryptkey == NULL && !*did_ask)
22c937
  	{
22c937
*** ../vim-7.4.402/src/option.c	2014-08-10 13:34:59.060785459 +0200
22c937
--- src/option.c	2014-08-13 21:48:49.924876683 +0200
22c937
***************
22c937
*** 6163,6168 ****
22c937
--- 6163,6176 ----
22c937
  		p_cm = vim_strsave((char_u *)"zip");
22c937
  		new_value_alloced = TRUE;
22c937
  	    }
22c937
+ 	    /* When using ":set cm=name" the local value is going to be empty.
22c937
+ 	     * Do that here, otherwise the crypt functions will still use the
22c937
+ 	     * local value. */
22c937
+ 	    if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
22c937
+ 	    {
22c937
+ 		free_string_option(curbuf->b_p_cm);
22c937
+ 		curbuf->b_p_cm = empty_option;
22c937
+ 	    }
22c937
  
22c937
  	    /* Need to update the swapfile when the effective method changed.
22c937
  	     * Set "s" to the effective old value, "p" to the effective new
22c937
*** ../vim-7.4.402/src/memline.c	2014-08-10 13:34:59.060785459 +0200
22c937
--- src/memline.c	2014-08-13 21:52:40.076880210 +0200
22c937
***************
22c937
*** 235,240 ****
22c937
--- 235,241 ----
22c937
  } upd_block0_T;
22c937
  
22c937
  #ifdef FEAT_CRYPT
22c937
+ static void ml_set_mfp_crypt __ARGS((buf_T *buf));
22c937
  static void ml_set_b0_crypt __ARGS((buf_T *buf, ZERO_BL *b0p));
22c937
  #endif
22c937
  static int ml_check_b0_id __ARGS((ZERO_BL *b0p));
22c937
***************
22c937
*** 433,438 ****
22c937
--- 434,458 ----
22c937
  
22c937
  #if defined(FEAT_CRYPT) || defined(PROTO)
22c937
  /*
22c937
+  * Prepare encryption for "buf" for the current key and method.
22c937
+  */
22c937
+     static void
22c937
+ ml_set_mfp_crypt(buf)
22c937
+     buf_T	*buf;
22c937
+ {
22c937
+     if (*buf->b_p_key != NUL)
22c937
+     {
22c937
+ 	int method_nr = crypt_get_method_nr(buf);
22c937
+ 
22c937
+ 	if (method_nr > CRYPT_M_ZIP)
22c937
+ 	{
22c937
+ 	    /* Generate a seed and store it in the memfile. */
22c937
+ 	    sha2_seed(buf->b_ml.ml_mfp->mf_seed, MF_SEED_LEN, NULL, 0);
22c937
+ 	}
22c937
+     }
22c937
+ }
22c937
+ 
22c937
+ /*
22c937
   * Prepare encryption for "buf" with block 0 "b0p".
22c937
   */
22c937
      static void
22c937
***************
22c937
*** 915,922 ****
22c937
      ZERO_BL	*b0p;
22c937
  
22c937
      mfp = buf->b_ml.ml_mfp;
22c937
!     if (mfp == NULL || (hp = mf_get(mfp, (blocknr_T)0, 1)) == NULL)
22c937
  	return;
22c937
      b0p = (ZERO_BL *)(hp->bh_data);
22c937
      if (ml_check_b0_id(b0p) == FAIL)
22c937
  	EMSG(_("E304: ml_upd_block0(): Didn't get block 0??"));
22c937
--- 935,953 ----
22c937
      ZERO_BL	*b0p;
22c937
  
22c937
      mfp = buf->b_ml.ml_mfp;
22c937
!     if (mfp == NULL)
22c937
! 	return;
22c937
!     hp = mf_get(mfp, (blocknr_T)0, 1);
22c937
!     if (hp == NULL)
22c937
!     {
22c937
! #ifdef FEAT_CRYPT
22c937
! 	/* Possibly update the seed in the memfile before there is a block0. */
22c937
! 	if (what == UB_CRYPT)
22c937
! 	    ml_set_mfp_crypt(buf);
22c937
! #endif
22c937
  	return;
22c937
+     }
22c937
+ 
22c937
      b0p = (ZERO_BL *)(hp->bh_data);
22c937
      if (ml_check_b0_id(b0p) == FAIL)
22c937
  	EMSG(_("E304: ml_upd_block0(): Didn't get block 0??"));
22c937
*** ../vim-7.4.402/src/version.c	2014-08-12 20:14:28.795371197 +0200
22c937
--- src/version.c	2014-08-13 17:23:02.964632329 +0200
22c937
***************
22c937
*** 743,744 ****
22c937
--- 743,746 ----
22c937
  {   /* Add new patch number below this line */
22c937
+ /**/
22c937
+     403,
22c937
  /**/
22c937
22c937
-- 
22c937
How To Keep A Healthy Level Of Insanity:
22c937
9. As often as possible, skip rather than walk.
22c937
22c937
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
22c937
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
22c937
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
22c937
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///