Patch 8.2.3218

4 views
Skip to first unread message

Bram Moolenaar

unread,
Jul 25, 2021, 8:36:38 AM7/25/21
to vim...@googlegroups.com

Patch 8.2.3218
Problem: When using xchaha20 crypt undo file is not removed.
Solution: Reset 'undofile' and delete the file. (Christian Brabandt,
closes #8630, closes #8467)
Files: src/bufwrite.c, src/crypt.c, src/proto/undo.pro,
src/testdir/test_crypt.vim, src/undo.c


*** ../vim-8.2.3217/src/bufwrite.c 2021-06-27 14:08:17.568112117 +0200
--- src/bufwrite.c 2021-07-25 14:34:06.405774807 +0200
***************
*** 1982,1989 ****
write_info.bw_start_lnum = start;

#ifdef FEAT_PERSISTENT_UNDO
- // TODO: if the selected crypt method prevents the undo file from being
- // written, and existing undo file should be deleted.
write_undo_file = (buf->b_p_udf
&& overwriting
&& !append
--- 1982,1987 ----
***************
*** 1991,2001 ****
# ifdef CRYPT_NOT_INPLACE
// writing undo file requires
// crypt_encode_inplace()
! && (curbuf->b_cryptstate == NULL
! || crypt_works_inplace(curbuf->b_cryptstate))
# endif
&& reset_changed
&& !checking_conversion);
if (write_undo_file)
// Prepare for computing the hash value of the text.
sha256_start(&sha_ctx);
--- 1989,2010 ----
# ifdef CRYPT_NOT_INPLACE
// writing undo file requires
// crypt_encode_inplace()
! && (buf->b_cryptstate == NULL
! || crypt_works_inplace(buf->b_cryptstate))
# endif
&& reset_changed
&& !checking_conversion);
+ # ifdef CRYPT_NOT_INPLACE
+ // remove undo file if encrypting it is not possible
+ if (buf->b_p_udf
+ && overwriting
+ && !append
+ && !filtering
+ && !checking_conversion
+ && buf->b_cryptstate != NULL
+ && !crypt_works_inplace(buf->b_cryptstate))
+ u_undofile_reset_and_delete(buf);
+ # endif
if (write_undo_file)
// Prepare for computing the hash value of the text.
sha256_start(&sha_ctx);
*** ../vim-8.2.3217/src/crypt.c 2021-06-21 21:08:04.928547486 +0200
--- src/crypt.c 2021-07-25 14:30:08.398224799 +0200
***************
*** 616,626 ****
// swap and undo files, so disable them
mf_close_file(curbuf, TRUE); // remove the swap file
set_option_value((char_u *)"swf", 0, NULL, OPT_LOCAL);
- #ifdef FEAT_PERSISTENT_UNDO
- set_option_value((char_u *)"udf", 0, NULL, OPT_LOCAL);
- #endif
msg_scroll = TRUE;
! msg(_("Note: Encryption of swapfile not supported, disabling swap- and undofile"));
}
}
#endif
--- 616,623 ----
// swap and undo files, so disable them
mf_close_file(curbuf, TRUE); // remove the swap file
set_option_value((char_u *)"swf", 0, NULL, OPT_LOCAL);
msg_scroll = TRUE;
! msg(_("Note: Encryption of swapfile not supported, disabling swap file"));
}
}
#endif
*** ../vim-8.2.3217/src/proto/undo.pro 2019-12-12 12:55:36.000000000 +0100
--- src/proto/undo.pro 2021-07-25 14:35:11.609649181 +0200
***************
*** 27,31 ****
--- 27,32 ----
int bufIsChangedNotTerm(buf_T *buf);
int curbufIsChanged(void);
void f_undofile(typval_T *argvars, typval_T *rettv);
+ void u_undofile_reset_and_delete(buf_T *buf);
void f_undotree(typval_T *argvars, typval_T *rettv);
/* vim: set ft=c : */
*** ../vim-8.2.3217/src/testdir/test_crypt.vim 2021-07-13 19:09:02.857482016 +0200
--- src/testdir/test_crypt.vim 2021-07-25 14:30:08.398224799 +0200
***************
*** 133,139 ****
catch
call assert_exception('pre-mature')
endtry
! call assert_match("Note: Encryption of swapfile not supported, disabling swap- and undofile", execute(':5messages'))

call assert_equal(0, &swapfile)
call assert_equal("xchacha20", &cryptmethod)
--- 133,139 ----
catch
call assert_exception('pre-mature')
endtry
! call assert_match("Note: Encryption of swapfile not supported, disabling swap file", execute(':5messages'))

call assert_equal(0, &swapfile)
call assert_equal("xchacha20", &cryptmethod)
***************
*** 152,158 ****
call feedkeys(":X\<CR>sodium\<CR>sodium\<CR>", 'xt')
" swapfile disabled
call assert_equal(0, &swapfile)
! call assert_match("Note: Encryption of swapfile not supported, disabling swap- and undofile", execute(':messages'))
w!
" encrypted using xchacha20
call assert_match("\[xchacha20\]", execute(':messages'))
--- 152,158 ----
call feedkeys(":X\<CR>sodium\<CR>sodium\<CR>", 'xt')
" swapfile disabled
call assert_equal(0, &swapfile)
! call assert_match("Note: Encryption of swapfile not supported, disabling swap file", execute(':messages'))
w!
" encrypted using xchacha20
call assert_match("\[xchacha20\]", execute(':messages'))
***************
*** 176,182 ****
sp Xcrypt_sodium_undo.txt
set cryptmethod=xchacha20 undofile
call feedkeys(":X\<CR>sodium\<CR>sodium\<CR>", 'xt')
! call assert_equal(0, &undofile)
let ufile=undofile(@%)
call append(0, ['monday', 'tuesday', 'wednesday', 'thursday', 'friday'])
call cursor(1, 1)
--- 176,182 ----
sp Xcrypt_sodium_undo.txt
set cryptmethod=xchacha20 undofile
call feedkeys(":X\<CR>sodium\<CR>sodium\<CR>", 'xt')
! call assert_equal(1, &undofile)
let ufile=undofile(@%)
call append(0, ['monday', 'tuesday', 'wednesday', 'thursday', 'friday'])
call cursor(1, 1)
***************
*** 189,194 ****
--- 189,195 ----
normal dd
set undolevels=100
w!
+ call assert_equal(0, &undofile)
bw!
call feedkeys(":sp Xcrypt_sodium_undo.txt\<CR>sodium\<CR>", 'xt')
" should fail
*** ../vim-8.2.3217/src/undo.c 2021-07-21 22:20:30.066401728 +0200
--- src/undo.c 2021-07-25 14:34:58.789674091 +0200
***************
*** 3669,3674 ****
--- 3669,3696 ----
rettv->vval.v_string = NULL;
#endif
}
+ #ifdef FEAT_PERSISTENT_UNDO
+ /*
+ * Reset undofile option and delete the undofile
+ */
+ void
+ u_undofile_reset_and_delete(buf_T *buf)
+ {
+ char_u *file_name;
+
+ if (!buf->b_p_udf)
+ return;
+
+ file_name = u_get_undo_file_name(buf->b_ffname, TRUE);
+ if (file_name != NULL)
+ {
+ mch_remove(file_name);
+ vim_free(file_name);
+ }
+
+ set_option_value((char_u *)"undofile", 0L, NULL, OPT_LOCAL);
+ }
+ #endif

/*
* "undotree()" function
*** ../vim-8.2.3217/src/version.c 2021-07-25 14:21:08.111502006 +0200
--- src/version.c 2021-07-25 14:35:48.549576864 +0200
***************
*** 757,758 ****
--- 757,760 ----
{ /* Add new patch number below this line */
+ /**/
+ 3218,
/**/

--
The term "free software" is defined by Richard M. Stallman as
being software that isn't necessarily for free. Confusing?
Let's call it "Stallman software" then!
-- Bram Moolenaar

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages