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