delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2003/01/09/14:32:00

Date: Thu, 09 Jan 2003 17:48:32 +0000
From: "Richard Dawe" <rich AT phekda DOT freeserve DOT co DOT uk>
Sender: rich AT phekda DOT freeserve DOT co DOT uk
To: djgpp-workers AT delorie DOT com
X-Mailer: Emacs 21.3.50 (via feedmail 8.3.emacs20_6 I) and Blat ver 1.8.6
Subject: /dev/zero & /dev/full support - open, link and unlink fixes [PATCH]
Message-Id: <E18Wgm1-0000dY-00@phekda.freeserve.co.uk>
Reply-To: djgpp-workers AT delorie DOT com

Hello.

Below is a patch fixing bugs in the /dev/zero and /dev/full support.
The bugs fixed are:

* open: Don't decide we're emulating until we've checked that /dev/zero
  or /dev/full (as appropriate) have been installed.

* link: Don't allow linking to or from /dev/{zero,full}.

* unlink: Check the filenames. If we're not trying to remove
  /dev/{zero,full}, then pass it through.

The last bug is pretty serious - it breaks an 'rm' that has been enabled
to understand /dev/zero and /dev/full. (Sorry about that.)

If there are no objections, I will commit this in a day or two.

Bye, Rich =]

Index: src/libc/fsext/fse_zero.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/fsext/fse_zero.c,v
retrieving revision 1.2
diff -p -u -3 -r1.2 fse_zero.c
--- src/libc/fsext/fse_zero.c	14 Jun 2002 09:11:07 -0000	1.2
+++ src/libc/fsext/fse_zero.c	9 Jan 2003 17:44:05 -0000
@@ -1,3 +1,4 @@
+/* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */
@@ -214,9 +215,6 @@ dev_fsext (__FSEXT_Fnumber n, int *rv, v
     if (   !match_dev_path(filename, DEV_ZERO_PATH)
 	&& !match_dev_path(filename, DEV_FULL_PATH))
       break;
-    
-    /* It's for us. */
-    emul = 1;
 
     /* Check whether the zero/full device has been installed. */
     if (match_dev_path(filename, DEV_ZERO_PATH) && !dev_zero_installed)
@@ -225,7 +223,10 @@ dev_fsext (__FSEXT_Fnumber n, int *rv, v
     if (match_dev_path(filename, DEV_FULL_PATH) && !dev_full_installed)
       break;
 
-    /* zero device _always_ exists. */
+    /* It's for us. */
+    emul = 1;
+
+    /* zero/full device _always_ exists, if installed. */
     if (open_mode & O_CREAT) {
       errno = EEXIST;
       *rv   = -1;	
@@ -576,16 +577,49 @@ dev_fsext (__FSEXT_Fnumber n, int *rv, v
     filename     = va_arg(args, char *);
     new_filename = va_arg(args, char *);
 
+    /* Check the filenames */
+    if (   !match_dev_path(filename, DEV_ZERO_PATH)
+	&& !match_dev_path(filename, DEV_FULL_PATH)
+        && !match_dev_path(new_filename, DEV_ZERO_PATH)
+	&& !match_dev_path(new_filename, DEV_FULL_PATH))
+      break;
+
+    /* Check whether the zero/full device has been installed. */
+    if (match_dev_path(filename, DEV_ZERO_PATH) && !dev_zero_installed)
+      break;
+
+    if (match_dev_path(filename, DEV_FULL_PATH) && !dev_full_installed)
+      break;
+
+    if (match_dev_path(new_filename, DEV_ZERO_PATH) && !dev_zero_installed)
+      break;
+
+    if (match_dev_path(new_filename, DEV_FULL_PATH) && !dev_full_installed)
+      break;
+
     /* This must be emulated, since the FSEXT has been called. */
     emul = 1;
 
     /* Fail request */
+    /* It doesn't make sense to link to or from /dev/zero or /dev/full. */
     errno = EPERM;
     *rv   = -1;
     break;
 
   case __FSEXT_unlink:
     filename = va_arg(args, char *);
+
+    /* Check the filename */
+    if (   !match_dev_path(filename, DEV_ZERO_PATH)
+	&& !match_dev_path(filename, DEV_FULL_PATH))
+      break;
+
+    /* Check whether the zero/full device has been installed. */
+    if (match_dev_path(filename, DEV_ZERO_PATH) && !dev_zero_installed)
+      break;
+
+    if (match_dev_path(filename, DEV_FULL_PATH) && !dev_full_installed)
+      break;
 
     /* This must be emulated, since the FSEXT has been called. */
     emul = 1;

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019