From a11b390609cf4b3315c4752a764148494b0a3b44 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Sat, 5 Sep 2009 06:39:17 -0600 Subject: [PATCH] test-openat-safer: add more checks * tests/test-openat-safer.c (main): Check more code paths. Signed-off-by: Eric Blake --- ChangeLog | 5 +++++ tests/test-openat-safer.c | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index c53c7f802e..938f6fd4e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-09-05 Eric Blake + + test-openat-safer: add more checks + * tests/test-openat-safer.c (main): Check more code paths. + 2009-09-05 Jim Meyering syntax-check: detect unnecessary inclusion of openat.h diff --git a/tests/test-openat-safer.c b/tests/test-openat-safer.c index a62477bfd3..47d3ada980 100644 --- a/tests/test-openat-safer.c +++ b/tests/test-openat-safer.c @@ -92,6 +92,9 @@ main () errno = 0; ASSERT (openat (dfd, "", O_RDONLY) == -1); ASSERT (errno == ENOENT); + errno = 0; + ASSERT (openat (-1, ".", O_RDONLY) == -1); + ASSERT (errno == EBADF); /* Check for trailing slash and /dev/null handling; the particular errno might be ambiguous. */ @@ -102,8 +105,13 @@ main () errno = 0; ASSERT (openat (dfd, "/dev/null/", O_RDONLY) == -1); /* ASSERT (errno == ENOTDIR); */ - fd = openat (dfd, "/dev/null", O_RDONLY); + /* Using a bad directory is okay for absolute paths. */ + fd = openat (-1, "/dev/null", O_WRONLY); ASSERT (STDERR_FILENO < fd); + /* Using a non-directory is wrong for relative paths. */ + errno = 0; + ASSERT (openat (fd, ".", O_RDONLY) == -1); + ASSERT (errno == EBADF || errno == ENOTDIR); ASSERT (close (fd) == 0); /* Check for our witness file. */ -- 2.30.2