From 2fd5e7b7562331be0150a89ea7b94be0bdbcc42b Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Mon, 18 Feb 2019 09:56:06 +0000 Subject: win32: avoid use of uninitialised metadata in stat(2) When additional metadata was being fetched the code for non-disk files used uninitialised data from the BY_HANDLE_FILE_INFORMATION structure. --- win32/mingw.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'win32') diff --git a/win32/mingw.c b/win32/mingw.c index 5cfba22f7..74cf56934 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -534,6 +534,11 @@ int mingw_fstat(int fd, struct mingw_stat *buf) buf->st_mtime = buf64.st_mtime; buf->st_ctime = buf64.st_ctime; buf->st_blocks = ((buf64.st_size+4095)>>12)<<3; +#if ENABLE_FEATURE_EXTRA_FILE_DATA + buf->st_dev = 0; + buf->st_ino = 0; + buf->st_nlink = S_ISDIR(buf->st_mode) ? 2 : 1; +#endif goto success; } @@ -545,13 +550,14 @@ int mingw_fstat(int fd, struct mingw_stat *buf) buf->st_mtime = filetime_to_time_t(&(fdata.ftLastWriteTime)); buf->st_ctime = filetime_to_time_t(&(fdata.ftCreationTime)); buf->st_blocks = ((buf->st_size+4095)>>12)<<3; - success: #if ENABLE_FEATURE_EXTRA_FILE_DATA buf->st_dev = fdata.dwVolumeSerialNumber; buf->st_ino = fdata.nFileIndexLow | (((uint64_t)fdata.nFileIndexHigh)<<32); buf->st_nlink = S_ISDIR(buf->st_mode) ? 2 : fdata.nNumberOfLinks; -#else +#endif + success: +#if !ENABLE_FEATURE_EXTRA_FILE_DATA buf->st_dev = 0; buf->st_ino = 0; buf->st_nlink = S_ISDIR(buf->st_mode) ? 2 : 1; -- cgit v1.2.3-55-g6feb