Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: "test -f $verybig" oversight



Hi,

At some point, the C02cond.ztst test does

  block=$(find /dev(|ices)/ -type b -print)

and then

  test -f $block

This is obviously an error in the test case.  

An interesting point is what then happens in getstat().  On my
host, $#block == 49263, that's a lot more than 4*PATH_MAX. Hence,
the following line

   stat(unmeta(s), &st);

causes "stat(NULL, &st)" to be called.  It's not clear wheter
this is safe or not.


Index: Test/C02cond.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/C02cond.ztst,v
retrieving revision 1.11
diff -u -r1.11 C02cond.ztst
--- Test/C02cond.ztst	10 Oct 2001 16:02:25 -0000	1.11
+++ Test/C02cond.ztst	29 Mar 2002 11:22:22 -0000
@@ -52,7 +52,12 @@
   [[ -e zerolength && ! -e nonexistent ]]
 0:-e cond
 
-  [[ -f zerolength && ! -f cond && ! -f $char && ! -f $block && ! -f . ]]
+  if [[ -n $block ]]; then
+    [[ -f zerolength && ! -f cond && ! -f $char && ! -f $block[(f)1] && ! -f . ]]
+  else
+    print -u8 'Warning: Not testing [[ -f blockdevice ]] (no devices found)'
+    [[ -f zerolength && ! -f cond && ! -f $char && ! -f . ]]
+  fi
 0:-f cond
 
   [[ -g modish && ! -g zerolength ]]
Index: Src/cond.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/cond.c,v
retrieving revision 1.3
diff -u -r1.3 cond.c
--- Src/cond.c	15 Oct 2001 11:28:08 -0000	1.3
+++ Src/cond.c	29 Mar 2002 11:22:23 -0000
@@ -324,6 +324,8 @@
 static struct stat *
 getstat(char *s)
 {
+    char *us;
+
 /* /dev/fd/n refers to the open file descriptor n.  We always use fstat *
  * in this case since on Solaris /dev/fd/n is a device special file     */
     if (!strncmp(s, "/dev/fd/", 8)) {
@@ -332,7 +334,9 @@
         return &st;
     }
 
-    if (stat(unmeta(s), &st))
+    if (!(us = unmeta(s)))
+        return NULL;
+    if (stat(us, &st))
 	return NULL;
     return &st;
 }


-- 
Alexandre Duret-Lutz



Messages sorted by: Reverse Date, Date, Thread, Author