From f2dc492df0f310aec97b5fc5847cca8d6cb70a33 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 22 Feb 2022 13:32:29 +0100 Subject: [PATCH] Cygwin: unlink: filter out virtual files and devices early on Signed-off-by: Corinna Vinschen --- winsup/cygwin/devices.h | 1 + winsup/cygwin/syscalls.cc | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/devices.h b/winsup/cygwin/devices.h index fbbde6ab9..8f718dd17 100644 --- a/winsup/cygwin/devices.h +++ b/winsup/cygwin/devices.h @@ -433,6 +433,7 @@ extern const _device dev_fs_storage; #define iscygdrive_dev(devn) (devn == FH_CYGDRIVE) #define isdev_dev(devn) (devn == FH_DEV) +#define isdevfd_dev(devn) (devn == FH_DEV_FD) #define isprocsys_dev(devn) (devn == FH_PROCSYS) diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 661c14347..24ec01da8 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -1123,7 +1123,11 @@ unlink (const char *ourname) set_errno (EROFS); goto done; } - + if (isdevfd_dev (devn) || (win32_name.isdevice () && !win32_name.issocket ())) + { + set_errno (EPERM); + goto done; + } if (!win32_name.exists ()) { debug_printf ("unlinking a nonexistent file");