Branch
Hash :
87555a59
Author :
Date :
2025-05-28T10:40:21
open, openat: handle O_DIRECTORY on special files On deficient platforms where we must check for directories ourselves when opening files, check before opening as well as after. This prevents a hang when trying to open a special file like a fifo in a context where a directory is required. Although there is still a race so we could still hang in a perverse situation, it’s the best we can do and it is better than hanging in the more-common case. * lib/open.c (lstatif): New static function. (open) [REPLACE_FCHDIR]: Also inspect O_CREAT. * lib/open.c (open), lib/openat.c (rpl_openat): When checking for directories, also do this before opening. Also, respect O_NOFOLLOW when checking for directories. * lib/openat.c: Remove a few more unnecessary differences from open.c. * modules/open (Depends-on): Depend on lstat. * modules/openat (Depends-on): Add fstatat. * modules/open-tests, modules/openat-tests: (configure.ac) Check for alarm decl. * tests/test-open.c, tests/test-openat.c: Include sys/stat.h, for mkfifo. [HAVE_DECL_ALARM]: Include signal.h, for alarm. * tests/test-open.h (test_open): Fail if test takes too long because we tried to open a fifo. Test opening /dev/null, /dev/tty and a fifo, with a trailing "/" and with O_DIRECTORY.
Files:
tests/test-openat.c
tests/test-open.h
tests/signature.h
tests/macros.h
Depends-on:
fcntl
mkfifo
symlink
configure.ac:
AC_CHECK_DECLS_ONCE([alarm])
Makefile.am:
TESTS += test-openat
check_PROGRAMS += test-openat
test_openat_LDADD = $(LDADD) @LIBINTL@