Author: kib
Date: Wed Sep  9 19:31:08 2015
New Revision: 287599
URL: https://svnweb.freebsd.org/changeset/base/287599

Log:
  For open("name", O_DIRECTORY | O_CREAT), do not try to create the
  named node, open(2) cannot create directories.  But do allow the flag
  combination to succeed if the directory already exists.
  
  Declare the open("name", O_DIRECTORY | O_CREAT | O_EXCL) always
  invalid for the same reason, since open(2) cannot create directory.
  
  Note that there is an argument that O_DIRECTORY | O_CREAT should be
  invalid always, regardless of the target directory existence or
  O_EXCL.  The current fix is conservative and allows the call to
  succeed in the situation where it succeeded before the patch.
  
  Reported by:  Tom Ridge <[email protected]>
  Reviewed by:  rwatson
  PR:    202892
  Sponsored by: The FreeBSD Foundation
  MFC after:    1 week

Modified:
  head/sys/kern/vfs_vnops.c

Modified: head/sys/kern/vfs_vnops.c
==============================================================================
--- head/sys/kern/vfs_vnops.c   Wed Sep  9 17:15:13 2015        (r287598)
+++ head/sys/kern/vfs_vnops.c   Wed Sep  9 19:31:08 2015        (r287599)
@@ -195,7 +195,10 @@ vn_open_cred(struct nameidata *ndp, int 
 
 restart:
        fmode = *flagp;
-       if (fmode & O_CREAT) {
+       if ((fmode & (O_CREAT | O_EXCL | O_DIRECTORY)) == (O_CREAT |
+           O_EXCL | O_DIRECTORY))
+               return (EINVAL);
+       else if ((fmode & (O_CREAT | O_DIRECTORY)) == O_CREAT) {
                ndp->ni_cnd.cn_nameiop = CREATE;
                /*
                 * Set NOCACHE to avoid flushing the cache when
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to