Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 11 Nov 1995 13:09:59 +1100
From:      Bruce Evans <bde@zeta.org.au>
To:        current@freebsd.org
Subject:   old bugs in vfs_lookup.c
Message-ID:  <199511110209.NAA01399@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
I've reported these bugs and fixes before but there wasn't enough
discussion.

1. The empty pathname is allowed as an alias for ".".  This breaks
   POSIX conformance for every syscall that involves a pathname.

2. lstat() depletes the namei cache.  Thus file system traversals
   often blow away the cache entries for everything they look at.

Bruce

*** vfs_lookup.c~	Mon Oct 23 01:47:39 1995
--- vfs_lookup.c	Mon Oct 23 01:47:40 1995
***************
*** 51,54 ****
--- 51,55 ----
  #include <sys/filedesc.h>
  #include <sys/proc.h>
+ #include <sys/syslog.h>
  
  #ifdef KTRACE
***************
*** 111,114 ****
--- 112,127 ----
  		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);
***************
*** 267,272 ****
  	wantparent = cnp->cn_flags & (LOCKPARENT | WANTPARENT);
  	docache = (cnp->cn_flags & NOCACHE) ^ NOCACHE;
  	if (cnp->cn_nameiop == DELETE ||
! 	    (wantparent && cnp->cn_nameiop != CREATE))
  		docache = 0;
  	rdonly = cnp->cn_flags & RDONLY;
--- 280,297 ----
  	wantparent = cnp->cn_flags & (LOCKPARENT | WANTPARENT);
  	docache = (cnp->cn_flags & NOCACHE) ^ NOCACHE;
+ 	/*
+ 	 * XXX the following seems to be just to recover from not setting
+ 	 * NOCACHE for the DELETE cases (unlink, rmdir and the rename
+ 	 * source).  In BSD4.4lite[2], docache was also cleared for the
+ 	 * (wantparent && cnp->cn_nameiop == LOOKUP) case.  This case
+ 	 * seems to only occur for lstat and olstat, when it is wrong
+ 	 * to clear docache.  This case probably didn't occur before
+ 	 * BSD4.4lite.  LOCKPARENT was introduced for lstat to support
+ 	 * the new behaviour of symlinks (attributes inherited from the
+ 	 * parent.
+ 	 */
  	if (cnp->cn_nameiop == DELETE ||
! 	    (wantparent && cnp->cn_nameiop != CREATE &&
! 	     cnp->cn_nameiop != LOOKUP))
  		docache = 0;
  	rdonly = cnp->cn_flags & RDONLY;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199511110209.NAA01399>