aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2002-06-05 16:01:55 +0000
committerChristopher Faylor <me@cgf.cx>2002-06-05 16:01:55 +0000
commitea4e6ec8f9fe4a784d4ce2ef71037e05fb9a876d (patch)
treef29a1b8689d3bc188ebc5d6822c1cbdb562e266d
parent2bb6b3e50619d10b93a8a2640dd4784e01e97236 (diff)
downloadnewlib-ea4e6ec8f9fe4a784d4ce2ef71037e05fb9a876d.zip
newlib-ea4e6ec8f9fe4a784d4ce2ef71037e05fb9a876d.tar.gz
newlib-ea4e6ec8f9fe4a784d4ce2ef71037e05fb9a876d.tar.bz2
* dir.cc (rmdir): Streamline. Detect attempts to remove directories from
"read-only" virtual devices. (Suggested by Pavel Tsekov) * syscalls.cc (unlink): Detect attempts to remove directories from "read-only" virtual devices. (From Pavel Tsekov)
-rw-r--r--winsup/cygwin/ChangeLog9
-rw-r--r--winsup/cygwin/dir.cc43
-rw-r--r--winsup/cygwin/syscalls.cc8
3 files changed, 34 insertions, 26 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 022f419..958c5d3 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,12 @@
2002-06-05 Christopher Faylor <cgf@redhat.com>
+ * dir.cc (rmdir): Streamline. Detect attempts to remove directories
+ from "read-only" virtual devices. (Suggested by Pavel Tsekov)
+ * syscalls.cc (unlink): Detect attempts to remove directories
+ from "read-only" virtual devices. (From Pavel Tsekov)
+
+2002-06-05 Christopher Faylor <cgf@redhat.com>
+
* dtable.cc (handle_to_fn): Check error return value from NtQueryObject
first before seeing if name buffer is NULL.
@@ -61,7 +68,7 @@
2002-06-04 Christopher Faylor <cgf@redhat.com>
* dtable.cc (handle_to_fn): Correct placement and length of name
- buffer. (Suggested by Pavel Tsekov)
+ buffer. (Suggested by Pavel Tsekov)
2002-06-04 Christopher Faylor <cgf@redhat.com>
diff --git a/winsup/cygwin/dir.cc b/winsup/cygwin/dir.cc
index c9509b6..45ba57f 100644
--- a/winsup/cygwin/dir.cc
+++ b/winsup/cygwin/dir.cc
@@ -273,24 +273,19 @@ extern "C" int
rmdir (const char *dir)
{
int res = -1;
+ DWORD devn;
path_conv real_dir (dir, PC_SYM_NOFOLLOW);
if (real_dir.error)
- {
- set_errno (real_dir.error);
- res = -1;
- }
+ set_errno (real_dir.error);
+ else if ((devn = real_dir.get_devn ()) == FH_PROC || devn == FH_REGISTRY
+ || devn == FH_PROCESS)
+ set_errno (EROFS);
else if (!real_dir.exists ())
- {
- set_errno (ENOENT);
- res = -1;
- }
+ set_errno (ENOENT);
else if (!real_dir.isdir ())
- {
- set_errno (ENOTDIR);
- res = -1;
- }
+ set_errno (ENOTDIR);
else
{
/* Even own directories can't be removed if R/O attribute is set. */
@@ -330,22 +325,20 @@ rmdir (const char *dir)
else if ((res = rmdir (dir)))
SetCurrentDirectory (cygheap->cwd.win32);
}
- if (GetLastError () == ERROR_ACCESS_DENIED)
+ if (res)
{
-
- /* On 9X ERROR_ACCESS_DENIED is returned if you try to remove
- a non-empty directory. */
- if (wincap.access_denied_on_delete ())
- set_errno (ENOTEMPTY);
- else
+ if (GetLastError () != ERROR_ACCESS_DENIED
+ || !wincap.access_denied_on_delete ())
__seterrno ();
- }
- else
- __seterrno ();
+ else
+ set_errno (ENOTEMPTY); /* On 9X ERROR_ACCESS_DENIED is
+ returned if you try to remove a
+ non-empty directory. */
- /* If directory still exists, restore R/O attribute. */
- if (real_dir.has_attribute (FILE_ATTRIBUTE_READONLY))
- SetFileAttributes (real_dir, real_dir);
+ /* If directory still exists, restore R/O attribute. */
+ if (real_dir.has_attribute (FILE_ATTRIBUTE_READONLY))
+ SetFileAttributes (real_dir, real_dir);
+ }
}
}
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 9e28d10..bf2709d 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -94,6 +94,7 @@ extern "C" int
_unlink (const char *ourname)
{
int res = -1;
+ DWORD devn;
sigframe thisframe (mainthread);
path_conv win32_name (ourname, PC_SYM_NOFOLLOW | PC_FULL);
@@ -104,6 +105,13 @@ _unlink (const char *ourname)
goto done;
}
+ if ((devn = win32_name.get_devn ()) == FH_PROC || devn == FH_REGISTRY
+ || devn == FH_PROCESS)
+ {
+ set_errno (EROFS);
+ goto done;
+ }
+
syscall_printf ("_unlink (%s)", win32_name.get_win32 ());
if (!win32_name.exists ())