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