From owner-freebsd-current Mon Sep 2 12:31:58 1996 Return-Path: owner-current Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id MAA08387 for current-outgoing; Mon, 2 Sep 1996 12:31:58 -0700 (PDT) Received: from godzilla.zeta.org.au (godzilla.zeta.org.au [203.2.228.19]) by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id MAA08382 for ; Mon, 2 Sep 1996 12:31:55 -0700 (PDT) Received: (from bde@localhost) by godzilla.zeta.org.au (8.6.12/8.6.9) id FAA32641; Tue, 3 Sep 1996 05:30:00 +1000 Date: Tue, 3 Sep 1996 05:30:00 +1000 From: Bruce Evans Message-Id: <199609021930.FAA32641@godzilla.zeta.org.au> To: jkh@time.cdrom.com, wollman@lcs.mit.edu Subject: Re: Anyone mind if I remove the following braindamage from test(1)? Cc: bde@zeta.org.au, freebsd-current@FreeBSD.org, joerg_wunsch@uriah.heep.sax.de Sender: owner-current@FreeBSD.org X-Loop: FreeBSD.org Precedence: bulk >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 #include + #include #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);