diff options
author | Ron Yorston <rmy@pobox.com> | 2018-03-15 09:01:45 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-03-15 09:01:45 +0000 |
commit | 94cf1f830d25409ba80b0933075e026e41fe0e3c (patch) | |
tree | f3a386872c52bb7c18283a4bca01dade3811d503 | |
parent | 6fe4ad9a6c96624c2b75c0d51b035bc1a71d9eba (diff) | |
download | busybox-w32-94cf1f830d25409ba80b0933075e026e41fe0e3c.tar.gz busybox-w32-94cf1f830d25409ba80b0933075e026e41fe0e3c.tar.bz2 busybox-w32-94cf1f830d25409ba80b0933075e026e41fe0e3c.zip |
win32: restrict visibility of special devices
Handling of the special devices /dev/zero and /dev/urandom was
inconsistent:
- they could be used as arguments to 'cat' but not 'od';
- they could not be used in shell redirection.
Restrict the use of these devices to two places:
- as input files to 'dd' with the 'if=' argument;
- internally within 'shred'.
See GitHub issue #98.
-rw-r--r-- | coreutils/dd.c | 4 | ||||
-rw-r--r-- | coreutils/shred.c | 4 | ||||
-rw-r--r-- | include/mingw.h | 2 | ||||
-rw-r--r-- | win32/mingw.c | 31 |
4 files changed, 33 insertions, 8 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c index 4362ae798..10066575e 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
@@ -429,8 +429,10 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
429 | #endif | 429 | #endif |
430 | 430 | ||
431 | if (infile) { | 431 | if (infile) { |
432 | #if !ENABLE_PLATFORM_MINGW32 | ||
432 | xmove_fd(xopen(infile, O_RDONLY), ifd); | 433 | xmove_fd(xopen(infile, O_RDONLY), ifd); |
433 | #if ENABLE_PLATFORM_MINGW32 | 434 | #else |
435 | xmove_fd(mingw_xopen(infile, O_RDONLY), ifd); | ||
434 | if (!strcmp(infile, "/dev/zero")) { | 436 | if (!strcmp(infile, "/dev/zero")) { |
435 | mingw_read_zero(ifd); | 437 | mingw_read_zero(ifd); |
436 | } | 438 | } |
diff --git a/coreutils/shred.c b/coreutils/shred.c index 1b65a359e..0ebbc39ca 100644 --- a/coreutils/shred.c +++ b/coreutils/shred.c | |||
@@ -38,6 +38,10 @@ | |||
38 | 38 | ||
39 | #include "libbb.h" | 39 | #include "libbb.h" |
40 | 40 | ||
41 | #if ENABLE_PLATFORM_MINGW32 | ||
42 | #define xopen mingw_xopen | ||
43 | #endif | ||
44 | |||
41 | int shred_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 45 | int shred_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
42 | int shred_main(int argc UNUSED_PARAM, char **argv) | 46 | int shred_main(int argc UNUSED_PARAM, char **argv) |
43 | { | 47 | { |
diff --git a/include/mingw.h b/include/mingw.h index 09903d582..386540b37 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
@@ -30,6 +30,7 @@ int inet_pton(int af, const char *src, void *dst); | |||
30 | #define FD_CLOEXEC 0x1 | 30 | #define FD_CLOEXEC 0x1 |
31 | #define O_NONBLOCK 0 | 31 | #define O_NONBLOCK 0 |
32 | #define O_NOFOLLOW 0 | 32 | #define O_NOFOLLOW 0 |
33 | #define O_SPECIAL 0x800000 | ||
33 | 34 | ||
34 | /* | 35 | /* |
35 | * grp.h | 36 | * grp.h |
@@ -367,6 +368,7 @@ int kill(pid_t pid, int sig); | |||
367 | int link(const char *oldpath, const char *newpath); | 368 | int link(const char *oldpath, const char *newpath); |
368 | NOIMPL(mknod,const char *name UNUSED_PARAM, mode_t mode UNUSED_PARAM, dev_t device UNUSED_PARAM); | 369 | NOIMPL(mknod,const char *name UNUSED_PARAM, mode_t mode UNUSED_PARAM, dev_t device UNUSED_PARAM); |
369 | int mingw_open (const char *filename, int oflags, ...); | 370 | int mingw_open (const char *filename, int oflags, ...); |
371 | int mingw_xopen(const char *filename, int oflags); | ||
370 | void mingw_read_zero(int fd); | 372 | void mingw_read_zero(int fd); |
371 | void mingw_read_random(int fd); | 373 | void mingw_read_random(int fd); |
372 | ssize_t mingw_read(int fd, void *buf, size_t count); | 374 | ssize_t mingw_read(int fd, void *buf, size_t count); |
diff --git a/win32/mingw.c b/win32/mingw.c index f9967f1c4..981c50415 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -157,6 +157,7 @@ int mingw_open (const char *filename, int oflags, ...) | |||
157 | va_list args; | 157 | va_list args; |
158 | unsigned mode; | 158 | unsigned mode; |
159 | int fd; | 159 | int fd; |
160 | int special = 0; | ||
160 | int devnull = 0; | 161 | int devnull = 0; |
161 | int devzero = 0; | 162 | int devzero = 0; |
162 | int devrand = 0; | 163 | int devrand = 0; |
@@ -165,16 +166,20 @@ int mingw_open (const char *filename, int oflags, ...) | |||
165 | mode = va_arg(args, int); | 166 | mode = va_arg(args, int); |
166 | va_end(args); | 167 | va_end(args); |
167 | 168 | ||
168 | if (oflags & O_NONBLOCK) { | 169 | if (oflags & O_SPECIAL) { |
169 | oflags &= ~O_NONBLOCK; | 170 | oflags &= ~O_SPECIAL; |
171 | special = 1; | ||
170 | } | 172 | } |
171 | if (filename && !strncmp(filename, "/dev/", 5)) { | 173 | if (filename && !strncmp(filename, "/dev/", 5)) { |
172 | if (!strcmp(filename+5, "null")) | 174 | if (!strcmp(filename+5, "null")) { |
173 | devnull = 1; | 175 | devnull = 1; |
174 | else if (!strcmp(filename+5, "zero")) | 176 | } |
175 | devzero = 1; | 177 | else if (special) { |
176 | else if (!strcmp(filename+5, "urandom")) | 178 | if (!strcmp(filename+5, "zero")) |
177 | devrand = 1; | 179 | devzero = 1; |
180 | else if (!strcmp(filename+5, "urandom")) | ||
181 | devrand = 1; | ||
182 | } | ||
178 | 183 | ||
179 | if (devnull || devzero || devrand ) | 184 | if (devnull || devzero || devrand ) |
180 | filename = "nul"; | 185 | filename = "nul"; |
@@ -194,6 +199,18 @@ int mingw_open (const char *filename, int oflags, ...) | |||
194 | return fd; | 199 | return fd; |
195 | } | 200 | } |
196 | 201 | ||
202 | int mingw_xopen(const char *pathname, int flags) | ||
203 | { | ||
204 | int ret; | ||
205 | |||
206 | /* allow use of special devices */ | ||
207 | ret = mingw_open(pathname, flags|O_SPECIAL); | ||
208 | if (ret < 0) { | ||
209 | bb_perror_msg_and_die("can't open '%s'", pathname); | ||
210 | } | ||
211 | return ret; | ||
212 | } | ||
213 | |||
197 | #undef fopen | 214 | #undef fopen |
198 | FILE *mingw_fopen (const char *filename, const char *otype) | 215 | FILE *mingw_fopen (const char *filename, const char *otype) |
199 | { | 216 | { |