From ec3bd5c462717a6cd1668f536c8aab9d76ea04b0 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sat, 20 Apr 2024 08:45:19 +0100 Subject: win32: make stat(2) fail for /dev/zero, /dev/urandom /dev/zero and /dev/urandom are only available internally and as arguments to 'dd'. Since users can't otherwise access them they shouldn't be treated as existing by stat(2). With this change stat(1) and test(1) will deny their existence. (GitHub issue #282) --- win32/mingw.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/win32/mingw.c b/win32/mingw.c index a8170bb9c..b1225665c 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -359,8 +359,9 @@ static int get_file_attr(const char *fname, WIN32_FILE_ATTRIBUTE_DATA *fdata) { char *want_dir; - if (get_dev_type(fname) != NOT_DEVICE || get_dev_fd(fname) >= 0) { + if (get_dev_type(fname) == DEV_NULL || get_dev_fd(fname) >= 0) { /* Fake attributes for special devices */ + /* Though not /dev/zero or /dev/urandom */ FILETIME epoch = {0xd53e8000, 0x019db1de}; // Unix epoch as FILETIME fdata->dwFileAttributes = FILE_ATTRIBUTE_DEVICE; fdata->ftCreationTime = fdata->ftLastAccessTime = -- cgit v1.2.3-55-g6feb