diff options
| author | Ron Yorston <rmy@pobox.com> | 2026-04-27 08:40:06 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2026-04-27 08:40:06 +0100 |
| commit | 750a5e863cc04584ba50722d8b003e279cd67d24 (patch) | |
| tree | d953baaf1f33fc2df901548f054ee60cc118fcb0 | |
| parent | 164015bc98835934ed6437107d874e6987ad9418 (diff) | |
| download | busybox-w32-750a5e863cc04584ba50722d8b003e279cd67d24.tar.gz busybox-w32-750a5e863cc04584ba50722d8b003e279cd67d24.tar.bz2 busybox-w32-750a5e863cc04584ba50722d8b003e279cd67d24.zip | |
win32: disable urandom/zero devices if dd is disabled
Support for /dev/urandom and /dev/zero relies on having a working
dd. If the dd applet is disabled attempts to access them should
fail.
Theoretically a third-party dd utility could also work, but let's
not encourage that sort of heresy.
| -rw-r--r-- | win32/mingw.c | 7 | ||||
| -rw-r--r-- | win32/popen.c | 7 |
2 files changed, 12 insertions, 2 deletions
diff --git a/win32/mingw.c b/win32/mingw.c index e58665c5b..254306222 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
| @@ -404,8 +404,13 @@ static inline mode_t file_attr_to_st_mode(DWORD attr) | |||
| 404 | static int get_file_attr(const char *fname, WIN32_FILE_ATTRIBUTE_DATA *fdata) | 404 | static int get_file_attr(const char *fname, WIN32_FILE_ATTRIBUTE_DATA *fdata) |
| 405 | { | 405 | { |
| 406 | char *want_dir; | 406 | char *want_dir; |
| 407 | int dev = get_dev_type(fname); | ||
| 407 | 408 | ||
| 408 | if (get_dev_type(fname) != NOT_DEVICE || get_dev_fd(fname) >= 0) { | 409 | #if !ENABLE_DD |
| 410 | // /dev/urandom and /dev/zero aren't supported without dd | ||
| 411 | if (dev != DEV_URANDOM && dev != DEV_ZERO) | ||
| 412 | #endif | ||
| 413 | if (dev != NOT_DEVICE || get_dev_fd(fname) >= 0) { | ||
| 409 | /* Fake attributes for special devices */ | 414 | /* Fake attributes for special devices */ |
| 410 | FILETIME epoch = {0xd53e8000, 0x019db1de}; // Unix epoch as FILETIME | 415 | FILETIME epoch = {0xd53e8000, 0x019db1de}; // Unix epoch as FILETIME |
| 411 | fdata->dwFileAttributes = FILE_ATTRIBUTE_DEVICE; | 416 | fdata->dwFileAttributes = FILE_ATTRIBUTE_DEVICE; |
diff --git a/win32/popen.c b/win32/popen.c index 4010608ce..daf481d42 100644 --- a/win32/popen.c +++ b/win32/popen.c | |||
| @@ -142,13 +142,18 @@ FILE *mingw_popen(const char *cmd, const char *mode) | |||
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | // Only called for /dev/urandom and /dev/zero | 144 | // Only called for /dev/urandom and /dev/zero |
| 145 | int mingw_popen_special(const char *device) | 145 | int mingw_popen_special(const char *device IF_NOT_DD(UNUSED_PARAM)) |
| 146 | { | 146 | { |
| 147 | #if ENABLE_DD | ||
| 147 | char cmd[32]; | 148 | char cmd[32]; |
| 148 | 149 | ||
| 149 | /* Create the pipe */ | 150 | /* Create the pipe */ |
| 150 | strcat(strcpy(cmd, "dd if="), device); | 151 | strcat(strcpy(cmd, "dd if="), device); |
| 151 | return mingw_popen_internal(NULL, "dd", cmd, "r", -1, NULL); | 152 | return mingw_popen_internal(NULL, "dd", cmd, "r", -1, NULL); |
| 153 | #else | ||
| 154 | errno = ENOSYS; | ||
| 155 | return -1; | ||
| 156 | #endif | ||
| 152 | } | 157 | } |
| 153 | 158 | ||
| 154 | /* | 159 | /* |
