mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 8.1.0773: not all crypt code is tested
Problem: Not all crypt code is tested. Solution: Disable unused crypt code. Add more test coverage.
This commit is contained in:
14
src/crypt.c
14
src/crypt.c
@@ -34,7 +34,9 @@ typedef struct {
|
||||
char *magic; /* magic bytes stored in file header */
|
||||
int salt_len; /* length of salt, or 0 when not using salt */
|
||||
int seed_len; /* length of seed, or 0 when not using salt */
|
||||
#ifdef CRYPT_NOT_INPLACE
|
||||
int works_inplace; /* encryption/decryption can be done in-place */
|
||||
#endif
|
||||
int whole_undofile; /* whole undo file is encrypted */
|
||||
|
||||
/* Optional function pointer for a self-test. */
|
||||
@@ -80,7 +82,9 @@ static cryptmethod_T cryptmethods[CRYPT_M_COUNT] = {
|
||||
"VimCrypt~01!",
|
||||
0,
|
||||
0,
|
||||
#ifdef CRYPT_NOT_INPLACE
|
||||
TRUE,
|
||||
#endif
|
||||
FALSE,
|
||||
NULL,
|
||||
crypt_zip_init,
|
||||
@@ -95,7 +99,9 @@ static cryptmethod_T cryptmethods[CRYPT_M_COUNT] = {
|
||||
"VimCrypt~02!",
|
||||
8,
|
||||
8,
|
||||
#ifdef CRYPT_NOT_INPLACE
|
||||
TRUE,
|
||||
#endif
|
||||
FALSE,
|
||||
blowfish_self_test,
|
||||
crypt_blowfish_init,
|
||||
@@ -110,7 +116,9 @@ static cryptmethod_T cryptmethods[CRYPT_M_COUNT] = {
|
||||
"VimCrypt~03!",
|
||||
8,
|
||||
8,
|
||||
#ifdef CRYPT_NOT_INPLACE
|
||||
TRUE,
|
||||
#endif
|
||||
TRUE,
|
||||
blowfish_self_test,
|
||||
crypt_blowfish_init,
|
||||
@@ -167,6 +175,7 @@ crypt_method_nr_from_magic(char *ptr, int len)
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef CRYPT_NOT_INPLACE
|
||||
/*
|
||||
* Return TRUE if the crypt method for "method_nr" can be done in-place.
|
||||
*/
|
||||
@@ -175,6 +184,7 @@ crypt_works_inplace(cryptstate_T *state)
|
||||
{
|
||||
return cryptmethods[state->method_nr].works_inplace;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Get the crypt method for buffer "buf" as a number.
|
||||
@@ -366,6 +376,7 @@ crypt_free_state(cryptstate_T *state)
|
||||
vim_free(state);
|
||||
}
|
||||
|
||||
#ifdef CRYPT_NOT_INPLACE
|
||||
/*
|
||||
* Encode "from[len]" and store the result in a newly allocated buffer, which
|
||||
* is stored in "newptr".
|
||||
@@ -422,6 +433,7 @@ crypt_decode_alloc(
|
||||
method->decode_fn(state, ptr, len, *newptr);
|
||||
return len;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Encrypting "from[len]" into "to[len]".
|
||||
@@ -436,6 +448,7 @@ crypt_encode(
|
||||
cryptmethods[state->method_nr].encode_fn(state, from, len, to);
|
||||
}
|
||||
|
||||
#if 0 // unused
|
||||
/*
|
||||
* decrypting "from[len]" into "to[len]".
|
||||
*/
|
||||
@@ -448,6 +461,7 @@ crypt_decode(
|
||||
{
|
||||
cryptmethods[state->method_nr].decode_fn(state, from, len, to);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Simple inplace encryption, modifies "buf[len]" in place.
|
||||
|
@@ -1381,9 +1381,12 @@ retry:
|
||||
if (cryptkey != NULL && curbuf->b_cryptstate != NULL
|
||||
&& size > 0)
|
||||
{
|
||||
# ifdef CRYPT_NOT_INPLACE
|
||||
if (crypt_works_inplace(curbuf->b_cryptstate))
|
||||
{
|
||||
# endif
|
||||
crypt_decode_inplace(curbuf->b_cryptstate, ptr, size);
|
||||
# ifdef CRYPT_NOT_INPLACE
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1434,6 +1437,7 @@ retry:
|
||||
}
|
||||
size = decrypted_size;
|
||||
}
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -5768,9 +5772,12 @@ buf_write_bytes(struct bw_info *ip)
|
||||
{
|
||||
/* Encrypt the data. Do it in-place if possible, otherwise use an
|
||||
* allocated buffer. */
|
||||
# ifdef CRYPT_NOT_INPLACE
|
||||
if (crypt_works_inplace(ip->bw_buffer->b_cryptstate))
|
||||
{
|
||||
# endif
|
||||
crypt_encode_inplace(ip->bw_buffer->b_cryptstate, buf, len);
|
||||
# ifdef CRYPT_NOT_INPLACE
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -5783,6 +5790,7 @@ buf_write_bytes(struct bw_info *ip)
|
||||
vim_free(outbuf);
|
||||
return (wlen < len) ? FAIL : OK;
|
||||
}
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@@ -1,7 +1,6 @@
|
||||
/* crypt.c */
|
||||
int crypt_method_nr_from_name(char_u *name);
|
||||
int crypt_method_nr_from_magic(char *ptr, int len);
|
||||
int crypt_works_inplace(cryptstate_T *state);
|
||||
int crypt_get_method_nr(buf_T *buf);
|
||||
int crypt_whole_undofile(int method_nr);
|
||||
int crypt_get_header_len(int method_nr);
|
||||
@@ -12,10 +11,7 @@ cryptstate_T *crypt_create_from_header(int method_nr, char_u *key, char_u *heade
|
||||
cryptstate_T *crypt_create_from_file(FILE *fp, char_u *key);
|
||||
cryptstate_T *crypt_create_for_writing(int method_nr, char_u *key, char_u **header, int *header_len);
|
||||
void crypt_free_state(cryptstate_T *state);
|
||||
long crypt_encode_alloc(cryptstate_T *state, char_u *from, size_t len, char_u **newptr);
|
||||
long crypt_decode_alloc(cryptstate_T *state, char_u *ptr, long len, char_u **newptr);
|
||||
void crypt_encode(cryptstate_T *state, char_u *from, size_t len, char_u *to);
|
||||
void crypt_decode(cryptstate_T *state, char_u *from, size_t len, char_u *to);
|
||||
void crypt_encode_inplace(cryptstate_T *state, char_u *buf, size_t len);
|
||||
void crypt_decode_inplace(cryptstate_T *state, char_u *buf, size_t len);
|
||||
void crypt_free_key(char_u *key);
|
||||
|
@@ -1940,6 +1940,10 @@ typedef struct {
|
||||
# define CRYPT_M_BF 1
|
||||
# define CRYPT_M_BF2 2
|
||||
# define CRYPT_M_COUNT 3 /* number of crypt methods */
|
||||
|
||||
// Currently all crypt methods work inplace. If one is added that isn't then
|
||||
// define this.
|
||||
// # define CRYPT_NOT_INPLACE 1
|
||||
#endif
|
||||
|
||||
|
||||
|
@@ -34,6 +34,7 @@ func Crypt_uncrypt(method)
|
||||
\ 'line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx']
|
||||
call setline(1, text)
|
||||
call feedkeys(":X\<CR>foobar\<CR>foobar\<CR>", 'xt')
|
||||
call assert_equal('*****', &key)
|
||||
w!
|
||||
bwipe!
|
||||
call feedkeys(":split Xtest.txt\<CR>foobar\<CR>", 'xt')
|
||||
@@ -81,3 +82,32 @@ endfunc
|
||||
func Test_uncrypt_blowfish2()
|
||||
call Uncrypt_stable('blowfish', "VimCrypt~03!\u001e\u00d1N\u00e3;\u00d3\u00c0\u00a0^C)\u0004\u00f7\u007f.\u00b6\u00abF\u000eS\u0019\u00e0\u008b6\u00d2[T\u00cb\u00a7\u0085\u00d8\u00be9\u000b\u00812\u000bQ\u00b3\u00cc@\u0097\u000f\u00df\u009a\u00adIv\u00aa.\u00d8\u00c9\u00ee\u009e`\u00bd$\u00af%\u00d0", "barburp", ["abcdefghijklmnopqrstuvwxyz", "!@#$%^&*()_+=-`~"])
|
||||
endfunc
|
||||
|
||||
func Test_uncrypt_unknown_method()
|
||||
split Xuncrypt_unknown.txt
|
||||
set bin noeol key= fenc=latin1
|
||||
call setline(1, "VimCrypt~93!\u001e\u00d1")
|
||||
w!
|
||||
bwipe!
|
||||
set nobin
|
||||
call assert_fails(":split Xuncrypt_unknown.txt", 'E821:')
|
||||
|
||||
bwipe!
|
||||
call delete('Xuncrypt_unknown.txt')
|
||||
set key=
|
||||
endfunc
|
||||
|
||||
func Test_crypt_key_mismatch()
|
||||
set cryptmethod=blowfish
|
||||
|
||||
split Xtest.txt
|
||||
call setline(1, 'nothing')
|
||||
call feedkeys(":X\<CR>foobar\<CR>nothing\<CR>", 'xt')
|
||||
call assert_match("Keys don't match!", execute(':2messages'))
|
||||
call assert_equal('', &key)
|
||||
call feedkeys("\<CR>\<CR>", 'xt')
|
||||
|
||||
set cryptmethod&
|
||||
bwipe!
|
||||
endfunc
|
||||
|
||||
|
@@ -791,6 +791,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
773,
|
||||
/**/
|
||||
772,
|
||||
/**/
|
||||
|
Reference in New Issue
Block a user