patch 8.0.0636: when reading the undo file fails may use uninitialized data

Problem:    When reading the undo file fails may use uninitialized data.
Solution:   Always clear the buffer on failure.
This commit is contained in:
Bram Moolenaar
2017-06-11 23:09:15 +02:00
parent 3a429efb62
commit 56f2db562d
2 changed files with 14 additions and 7 deletions

View File

@ -1063,6 +1063,8 @@ undo_read_time(bufinfo_T *bi)
static int static int
undo_read(bufinfo_T *bi, char_u *buffer, size_t size) undo_read(bufinfo_T *bi, char_u *buffer, size_t size)
{ {
int retval = OK;
#ifdef FEAT_CRYPT #ifdef FEAT_CRYPT
if (bi->bi_buffer != NULL) if (bi->bi_buffer != NULL)
{ {
@ -1078,10 +1080,8 @@ undo_read(bufinfo_T *bi, char_u *buffer, size_t size)
n = fread(bi->bi_buffer, 1, (size_t)CRYPT_BUF_SIZE, bi->bi_fp); n = fread(bi->bi_buffer, 1, (size_t)CRYPT_BUF_SIZE, bi->bi_fp);
if (n == 0) if (n == 0)
{ {
/* Error may be checked for only later. Fill with zeros, retval = FAIL;
* so that the reader won't use garbage. */ break;
vim_memset(p, 0, size_todo);
return FAIL;
} }
bi->bi_avail = n; bi->bi_avail = n;
bi->bi_used = 0; bi->bi_used = 0;
@ -1095,12 +1095,17 @@ undo_read(bufinfo_T *bi, char_u *buffer, size_t size)
size_todo -= (int)n; size_todo -= (int)n;
p += n; p += n;
} }
return OK;
} }
else
#endif #endif
if (fread(buffer, (size_t)size, 1, bi->bi_fp) != 1) if (fread(buffer, (size_t)size, 1, bi->bi_fp) != 1)
return FAIL; retval = FAIL;
return OK;
if (retval == FAIL)
/* Error may be checked for only later. Fill with zeros,
* so that the reader won't use garbage. */
vim_memset(buffer, 0, size);
return retval;
} }
/* /*

View File

@ -764,6 +764,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 */
/**/
636,
/**/ /**/
635, 635,
/**/ /**/