mirror of
https://github.com/vim/vim.git
synced 2025-10-08 06:04:08 -04:00
patch 7.4.730
Problem: When setting the crypt key and using a swap file, text may be encrypted twice or unencrypted text remains in the swap file. (Issue 369) Solution: Call ml_preserve() before re-encrypting. Set correct index for next pointer block.
This commit is contained in:
@@ -811,6 +811,8 @@ mf_rem_used(mfp, hp)
|
|||||||
*
|
*
|
||||||
* Return the block header to the caller, including the memory block, so
|
* Return the block header to the caller, including the memory block, so
|
||||||
* it can be re-used. Make sure the page_count is right.
|
* it can be re-used. Make sure the page_count is right.
|
||||||
|
*
|
||||||
|
* Returns NULL if no block is released.
|
||||||
*/
|
*/
|
||||||
static bhdr_T *
|
static bhdr_T *
|
||||||
mf_release(mfp, page_count)
|
mf_release(mfp, page_count)
|
||||||
@@ -1219,7 +1221,7 @@ mf_trans_add(mfp, hp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Lookup a translation from the trans lists and delete the entry
|
* Lookup a translation from the trans lists and delete the entry.
|
||||||
*
|
*
|
||||||
* Return the positive new number when found, the old number when not found
|
* Return the positive new number when found, the old number when not found
|
||||||
*/
|
*/
|
||||||
|
@@ -488,7 +488,7 @@ ml_set_b0_crypt(buf, b0p)
|
|||||||
ml_set_crypt_key(buf, old_key, old_cm)
|
ml_set_crypt_key(buf, old_key, old_cm)
|
||||||
buf_T *buf;
|
buf_T *buf;
|
||||||
char_u *old_key;
|
char_u *old_key;
|
||||||
int old_cm;
|
char_u *old_cm;
|
||||||
{
|
{
|
||||||
memfile_T *mfp = buf->b_ml.ml_mfp;
|
memfile_T *mfp = buf->b_ml.ml_mfp;
|
||||||
bhdr_T *hp;
|
bhdr_T *hp;
|
||||||
@@ -500,15 +500,30 @@ ml_set_crypt_key(buf, old_key, old_cm)
|
|||||||
DATA_BL *dp;
|
DATA_BL *dp;
|
||||||
blocknr_T bnum;
|
blocknr_T bnum;
|
||||||
int top;
|
int top;
|
||||||
|
int old_method;
|
||||||
|
|
||||||
if (mfp == NULL)
|
if (mfp == NULL)
|
||||||
return; /* no memfile yet, nothing to do */
|
return; /* no memfile yet, nothing to do */
|
||||||
|
old_method = crypt_method_nr_from_name(old_cm);
|
||||||
|
|
||||||
|
/* First make sure the swapfile is in a consistent state, using the old
|
||||||
|
* key and method. */
|
||||||
|
{
|
||||||
|
char_u *new_key = buf->b_p_key;
|
||||||
|
char_u *new_buf_cm = buf->b_p_cm;
|
||||||
|
|
||||||
|
buf->b_p_key = old_key;
|
||||||
|
buf->b_p_cm = old_cm;
|
||||||
|
ml_preserve(buf, FALSE);
|
||||||
|
buf->b_p_key = new_key;
|
||||||
|
buf->b_p_cm = new_buf_cm;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set the key, method and seed to be used for reading, these must be the
|
/* Set the key, method and seed to be used for reading, these must be the
|
||||||
* old values. */
|
* old values. */
|
||||||
mfp->mf_old_key = old_key;
|
mfp->mf_old_key = old_key;
|
||||||
mfp->mf_old_cm = old_cm;
|
mfp->mf_old_cm = old_method;
|
||||||
if (old_cm > 0)
|
if (old_method > 0 && *old_key != NUL)
|
||||||
mch_memmove(mfp->mf_old_seed, mfp->mf_seed, MF_SEED_LEN);
|
mch_memmove(mfp->mf_old_seed, mfp->mf_seed, MF_SEED_LEN);
|
||||||
|
|
||||||
/* Update block 0 with the crypt flag and may set a new seed. */
|
/* Update block 0 with the crypt flag and may set a new seed. */
|
||||||
@@ -561,8 +576,10 @@ ml_set_crypt_key(buf, old_key, old_cm)
|
|||||||
{
|
{
|
||||||
if (pp->pb_pointer[idx].pe_bnum < 0)
|
if (pp->pb_pointer[idx].pe_bnum < 0)
|
||||||
{
|
{
|
||||||
/* Skip data block with negative block number. */
|
/* Skip data block with negative block number.
|
||||||
++idx; /* get same block again for next index */
|
* Should not happen, because of the ml_preserve()
|
||||||
|
* above. Get same block again for next index. */
|
||||||
|
++idx;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -579,6 +596,7 @@ ml_set_crypt_key(buf, old_key, old_cm)
|
|||||||
|
|
||||||
bnum = pp->pb_pointer[idx].pe_bnum;
|
bnum = pp->pb_pointer[idx].pe_bnum;
|
||||||
page_count = pp->pb_pointer[idx].pe_page_count;
|
page_count = pp->pb_pointer[idx].pe_page_count;
|
||||||
|
idx = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -605,6 +623,8 @@ ml_set_crypt_key(buf, old_key, old_cm)
|
|||||||
idx = ip->ip_index + 1; /* go to next index */
|
idx = ip->ip_index + 1; /* go to next index */
|
||||||
page_count = 1;
|
page_count = 1;
|
||||||
}
|
}
|
||||||
|
if (hp != NULL)
|
||||||
|
mf_put(mfp, hp, FALSE, FALSE); /* release previous block */
|
||||||
|
|
||||||
if (error > 0)
|
if (error > 0)
|
||||||
EMSG(_("E843: Error while updating swap file crypt"));
|
EMSG(_("E843: Error while updating swap file crypt"));
|
||||||
@@ -4859,6 +4879,10 @@ ml_encrypt_data(mfp, data, offset, size)
|
|||||||
if (dp->db_id != DATA_ID)
|
if (dp->db_id != DATA_ID)
|
||||||
return data;
|
return data;
|
||||||
|
|
||||||
|
state = ml_crypt_prepare(mfp, offset, FALSE);
|
||||||
|
if (state == NULL)
|
||||||
|
return data;
|
||||||
|
|
||||||
new_data = (char_u *)alloc(size);
|
new_data = (char_u *)alloc(size);
|
||||||
if (new_data == NULL)
|
if (new_data == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -4870,7 +4894,6 @@ ml_encrypt_data(mfp, data, offset, size)
|
|||||||
mch_memmove(new_data, dp, head_end - (char_u *)dp);
|
mch_memmove(new_data, dp, head_end - (char_u *)dp);
|
||||||
|
|
||||||
/* Encrypt the text. */
|
/* Encrypt the text. */
|
||||||
state = ml_crypt_prepare(mfp, offset, FALSE);
|
|
||||||
crypt_encode(state, text_start, text_len, new_data + dp->db_txt_start);
|
crypt_encode(state, text_start, text_len, new_data + dp->db_txt_start);
|
||||||
crypt_free_state(state);
|
crypt_free_state(state);
|
||||||
|
|
||||||
@@ -4882,7 +4905,7 @@ ml_encrypt_data(mfp, data, offset, size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Decrypt the text in "data" if it points to a data block.
|
* Decrypt the text in "data" if it points to an encrypted data block.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
ml_decrypt_data(mfp, data, offset, size)
|
ml_decrypt_data(mfp, data, offset, size)
|
||||||
@@ -4907,11 +4930,14 @@ ml_decrypt_data(mfp, data, offset, size)
|
|||||||
|| dp->db_txt_end > size)
|
|| dp->db_txt_end > size)
|
||||||
return; /* data was messed up */
|
return; /* data was messed up */
|
||||||
|
|
||||||
/* Decrypt the text in place. */
|
|
||||||
state = ml_crypt_prepare(mfp, offset, TRUE);
|
state = ml_crypt_prepare(mfp, offset, TRUE);
|
||||||
|
if (state != NULL)
|
||||||
|
{
|
||||||
|
/* Decrypt the text in place. */
|
||||||
crypt_decode_inplace(state, text_start, text_len);
|
crypt_decode_inplace(state, text_start, text_len);
|
||||||
crypt_free_state(state);
|
crypt_free_state(state);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -4943,6 +4969,8 @@ ml_crypt_prepare(mfp, offset, reading)
|
|||||||
key = buf->b_p_key;
|
key = buf->b_p_key;
|
||||||
seed = mfp->mf_seed;
|
seed = mfp->mf_seed;
|
||||||
}
|
}
|
||||||
|
if (*key == NUL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if (method_nr == CRYPT_M_ZIP)
|
if (method_nr == CRYPT_M_ZIP)
|
||||||
{
|
{
|
||||||
|
@@ -6163,7 +6163,8 @@ did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
|
|||||||
# endif
|
# endif
|
||||||
if (STRCMP(curbuf->b_p_key, oldval) != 0)
|
if (STRCMP(curbuf->b_p_key, oldval) != 0)
|
||||||
/* Need to update the swapfile. */
|
/* Need to update the swapfile. */
|
||||||
ml_set_crypt_key(curbuf, oldval, crypt_get_method_nr(curbuf));
|
ml_set_crypt_key(curbuf, oldval,
|
||||||
|
*curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (gvarp == &p_cm)
|
else if (gvarp == &p_cm)
|
||||||
@@ -6207,8 +6208,7 @@ did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
|
|||||||
else
|
else
|
||||||
p = curbuf->b_p_cm;
|
p = curbuf->b_p_cm;
|
||||||
if (STRCMP(s, p) != 0)
|
if (STRCMP(s, p) != 0)
|
||||||
ml_set_crypt_key(curbuf, curbuf->b_p_key,
|
ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
|
||||||
crypt_method_nr_from_name(s));
|
|
||||||
|
|
||||||
/* If the global value changes need to update the swapfile for all
|
/* If the global value changes need to update the swapfile for all
|
||||||
* buffers using that value. */
|
* buffers using that value. */
|
||||||
@@ -6218,8 +6218,7 @@ did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
|
|||||||
|
|
||||||
for (buf = firstbuf; buf != NULL; buf = buf->b_next)
|
for (buf = firstbuf; buf != NULL; buf = buf->b_next)
|
||||||
if (buf != curbuf && *buf->b_p_cm == NUL)
|
if (buf != curbuf && *buf->b_p_cm == NUL)
|
||||||
ml_set_crypt_key(buf, buf->b_p_key,
|
ml_set_crypt_key(buf, buf->b_p_key, oldval);
|
||||||
crypt_method_nr_from_name(oldval));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/* memline.c */
|
/* memline.c */
|
||||||
int ml_open __ARGS((buf_T *buf));
|
int ml_open __ARGS((buf_T *buf));
|
||||||
void ml_set_crypt_key __ARGS((buf_T *buf, char_u *old_key, int old_cm));
|
void ml_set_crypt_key __ARGS((buf_T *buf, char_u *old_key, char_u *old_cm));
|
||||||
void ml_setname __ARGS((buf_T *buf));
|
void ml_setname __ARGS((buf_T *buf));
|
||||||
void ml_open_files __ARGS((void));
|
void ml_open_files __ARGS((void));
|
||||||
void ml_open_file __ARGS((buf_T *buf));
|
void ml_open_file __ARGS((buf_T *buf));
|
||||||
|
@@ -741,6 +741,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
730,
|
||||||
/**/
|
/**/
|
||||||
729,
|
729,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user