vim-patch:8.0.0636: when reading the undo file fails may use uninitialized data (#8599)

Problem:    When reading the undo file fails may use uninitialized data.
Solution:   Always clear the buffer on failure.
56f2db562d
This commit is contained in:
Jan Edmund Lazo 2018-06-19 20:29:52 -04:00 committed by Justin M. Keyes
parent 6294a807d3
commit 6e55c5997e

View File

@ -1635,7 +1635,13 @@ static time_t undo_read_time(bufinfo_T *bi)
static bool undo_read(bufinfo_T *bi, uint8_t *buffer, size_t size)
FUNC_ATTR_NONNULL_ARG(1)
{
return fread(buffer, size, 1, bi->bi_fp) == 1;
const bool retval = fread(buffer, size, 1, bi->bi_fp) == 1;
if (!retval) {
// Error may be checked for only later. Fill with zeros,
// so that the reader won't use garbage.
memset(buffer, 0, size);
}
return retval;
}
/// Reads a string of length "len" from "bi->bi_fd" and appends a zero to it.
@ -2443,7 +2449,7 @@ static void u_undo_end(
*/
void
u_sync(
int force /* Also sync when no_u_sync is set. */
int force // Also sync when no_u_sync is set.
)
{
/* Skip it when already synced or syncing is disabled. */
@ -2719,7 +2725,7 @@ static void
u_freeheader(
buf_T *buf,
u_header_T *uhp,
u_header_T **uhpp /* if not NULL reset when freeing this header */
u_header_T **uhpp // if not NULL reset when freeing this header
)
{
u_header_T *uhap;
@ -2755,7 +2761,7 @@ static void
u_freebranch(
buf_T *buf,
u_header_T *uhp,
u_header_T **uhpp /* if not NULL reset when freeing this header */
u_header_T **uhpp // if not NULL reset when freeing this header
)
{
u_header_T *tofree, *next;
@ -2789,7 +2795,7 @@ static void
u_freeentries(
buf_T *buf,
u_header_T *uhp,
u_header_T **uhpp /* if not NULL reset when freeing this header */
u_header_T **uhpp // if not NULL reset when freeing this header
)
{
u_entry_T *uep, *nuep;