aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2019-02-18 09:56:06 +0000
committerRon Yorston <rmy@pobox.com>2019-02-18 09:56:06 +0000
commit2fd5e7b7562331be0150a89ea7b94be0bdbcc42b (patch)
tree33b865e758a7319c4f5c77088bd99a04eb37687d
parentb1dcae0da4f5e9713fd54678ec42709a1744474b (diff)
downloadbusybox-w32-2fd5e7b7562331be0150a89ea7b94be0bdbcc42b.tar.gz
busybox-w32-2fd5e7b7562331be0150a89ea7b94be0bdbcc42b.tar.bz2
busybox-w32-2fd5e7b7562331be0150a89ea7b94be0bdbcc42b.zip
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.
-rw-r--r--win32/mingw.c10
1 files changed, 8 insertions, 2 deletions
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)
534 buf->st_mtime = buf64.st_mtime; 534 buf->st_mtime = buf64.st_mtime;
535 buf->st_ctime = buf64.st_ctime; 535 buf->st_ctime = buf64.st_ctime;
536 buf->st_blocks = ((buf64.st_size+4095)>>12)<<3; 536 buf->st_blocks = ((buf64.st_size+4095)>>12)<<3;
537#if ENABLE_FEATURE_EXTRA_FILE_DATA
538 buf->st_dev = 0;
539 buf->st_ino = 0;
540 buf->st_nlink = S_ISDIR(buf->st_mode) ? 2 : 1;
541#endif
537 goto success; 542 goto success;
538 } 543 }
539 544
@@ -545,13 +550,14 @@ int mingw_fstat(int fd, struct mingw_stat *buf)
545 buf->st_mtime = filetime_to_time_t(&(fdata.ftLastWriteTime)); 550 buf->st_mtime = filetime_to_time_t(&(fdata.ftLastWriteTime));
546 buf->st_ctime = filetime_to_time_t(&(fdata.ftCreationTime)); 551 buf->st_ctime = filetime_to_time_t(&(fdata.ftCreationTime));
547 buf->st_blocks = ((buf->st_size+4095)>>12)<<3; 552 buf->st_blocks = ((buf->st_size+4095)>>12)<<3;
548 success:
549#if ENABLE_FEATURE_EXTRA_FILE_DATA 553#if ENABLE_FEATURE_EXTRA_FILE_DATA
550 buf->st_dev = fdata.dwVolumeSerialNumber; 554 buf->st_dev = fdata.dwVolumeSerialNumber;
551 buf->st_ino = fdata.nFileIndexLow | 555 buf->st_ino = fdata.nFileIndexLow |
552 (((uint64_t)fdata.nFileIndexHigh)<<32); 556 (((uint64_t)fdata.nFileIndexHigh)<<32);
553 buf->st_nlink = S_ISDIR(buf->st_mode) ? 2 : fdata.nNumberOfLinks; 557 buf->st_nlink = S_ISDIR(buf->st_mode) ? 2 : fdata.nNumberOfLinks;
554#else 558#endif
559 success:
560#if !ENABLE_FEATURE_EXTRA_FILE_DATA
555 buf->st_dev = 0; 561 buf->st_dev = 0;
556 buf->st_ino = 0; 562 buf->st_ino = 0;
557 buf->st_nlink = S_ISDIR(buf->st_mode) ? 2 : 1; 563 buf->st_nlink = S_ISDIR(buf->st_mode) ? 2 : 1;