aboutsummaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2018-03-15 09:01:45 +0000
committerRon Yorston <rmy@pobox.com>2018-03-15 09:01:45 +0000
commit94cf1f830d25409ba80b0933075e026e41fe0e3c (patch)
treef3a386872c52bb7c18283a4bca01dade3811d503 /win32
parent6fe4ad9a6c96624c2b75c0d51b035bc1a71d9eba (diff)
downloadbusybox-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.
Diffstat (limited to 'win32')
-rw-r--r--win32/mingw.c31
1 files changed, 24 insertions, 7 deletions
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
202int 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
198FILE *mingw_fopen (const char *filename, const char *otype) 215FILE *mingw_fopen (const char *filename, const char *otype)
199{ 216{