Skip to content

Commit 56f2db5

Browse files
committed
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.
1 parent 3a429ef commit 56f2db5

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/undo.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,8 @@ undo_read_time(bufinfo_T *bi)
10631063
static int
10641064
undo_read(bufinfo_T *bi, char_u *buffer, size_t size)
10651065
{
1066+
int retval = OK;
1067+
10661068
#ifdef FEAT_CRYPT
10671069
if (bi->bi_buffer != NULL)
10681070
{
@@ -1078,10 +1080,8 @@ undo_read(bufinfo_T *bi, char_u *buffer, size_t size)
10781080
n = fread(bi->bi_buffer, 1, (size_t)CRYPT_BUF_SIZE, bi->bi_fp);
10791081
if (n == 0)
10801082
{
1081-
/* Error may be checked for only later. Fill with zeros,
1082-
* so that the reader won't use garbage. */
1083-
vim_memset(p, 0, size_todo);
1084-
return FAIL;
1083+
retval = FAIL;
1084+
break;
10851085
}
10861086
bi->bi_avail = n;
10871087
bi->bi_used = 0;
@@ -1095,12 +1095,17 @@ undo_read(bufinfo_T *bi, char_u *buffer, size_t size)
10951095
size_todo -= (int)n;
10961096
p += n;
10971097
}
1098-
return OK;
10991098
}
1099+
else
11001100
#endif
11011101
if (fread(buffer, (size_t)size, 1, bi->bi_fp) != 1)
1102-
return FAIL;
1103-
return OK;
1102+
retval = FAIL;
1103+
1104+
if (retval == FAIL)
1105+
/* Error may be checked for only later. Fill with zeros,
1106+
* so that the reader won't use garbage. */
1107+
vim_memset(buffer, 0, size);
1108+
return retval;
11041109
}
11051110

11061111
/*

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
636,
767769
/**/
768770
635,
769771
/**/

0 commit comments

Comments
 (0)