Date: Tue, 3 Sep 1996 05:30:00 +1000 From: Bruce Evans <bde@zeta.org.au> To: jkh@time.cdrom.com, wollman@lcs.mit.edu Cc: bde@zeta.org.au, freebsd-current@FreeBSD.org, joerg_wunsch@uriah.heep.sax.de Subject: Re: Anyone mind if I remove the following braindamage from test(1)? Message-ID: <199609021930.FAA32641@godzilla.zeta.org.au>
next in thread | raw e-mail | index | archive | help
>Use:
> [ -d "$foo" ]
>instead of
> [ -d $foo ]
>. This will ensure that two arguments get passed to the `-d'
>primitive, even if $foo is not defined.
This only works right on POSIX systems. Under FreeBSD, "" is
an alias for ".", so if $foo is empty,
[ -d "$foo" ]
almost always succeeds.
There is also a bug in bash's builtin test. On freefall:
$bash test -d ''; echo $?
1
$bash /bin/test -d ''; echo $?
0
I have used this fix for a year or three. I fixed empty pathnames in
many programs but there are still several standard programs with
harmless bugs in this area. Tar apparently strips one too many
slash from "/", and there's a rare case in gzip where it does a
harmless stat() of "".
Bruce
diff -c2 src/sys/kern/vfs_lookup.c~ src/sys/kern/vfs_lookup.c
*** src/sys/kern/vfs_lookup.c~ Thu Jan 4 17:07:54 1996
--- src/sys/kern/vfs_lookup.c Wed Mar 6 17:58:20 1996
***************
*** 53,56 ****
--- 53,57 ----
#include <sys/filedesc.h>
#include <sys/proc.h>
+ #include <sys/syslog.h>
#ifdef KTRACE
***************
*** 113,116 ****
--- 114,129 ----
error = copyinstr(ndp->ni_dirp, cnp->cn_pnbuf,
MAXPATHLEN, (u_int *)&ndp->ni_pathlen);
+
+ /*
+ * Don't allow empty pathname.
+ * Log the error until we find the standard utilities that cause it.
+ */
+ if (!error && *cnp->cn_pnbuf == '\0') {
+ log(LOG_ERR,
+ "pid %d (%s) called namei with an empty pathname\n",
+ cnp->cn_proc->p_pid, cnp->cn_proc->p_comm);
+ error = ENOENT;
+ }
+
if (error) {
free(cnp->cn_pnbuf, M_NAMEI);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199609021930.FAA32641>
