Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There is the non-standard O_NOFOLLOW.


Why do you say "non-standard"? O_NOFOLLOW is specified by POSIX.


The Linux manual page is a little misleading, and I didn't dig further into POSIX. Mea culpa.

       O_NOFOLLOW
              If pathname is a symbolic link, then the open fails.  This is a FreeBSD extension, which was added  to  Linux  in  version
              2.1.126.  Symbolic links in earlier components of the pathname will still be followed.  See also O_PATH below.
...

       The O_CLOEXEC, O_DIRECTORY, and O_NOFOLLOW flags are not specified in POSIX.1-2001, but are  specified  in  POSIX.1-2008.


Can you not do an ordinary open without O_NOFOLLOW and then lstat the filename?


Race condition again. The file could be unlinked. fstat is the only safe way of getting stat information for an open file.


Right. The right thing to do is open() with NOFOLLOW, then fstat the resulting fd. Then check for S_ISLNK(st_mode).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: