bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

openat-safer: Avoid test failure on NetBSD 8


From: Bruno Haible
Subject: openat-safer: Avoid test failure on NetBSD 8
Date: Sun, 16 Dec 2018 00:49:49 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-139-generic; KDE/5.18.0; x86_64; ; )

While testing a grep snapshot on NetBSD 8, I see that the gnulib test
'test-openat-safer' fails:

FAIL: test-openat-safer
=======================

../../gnulib-tests/test-openat-safer.c:101: assertion 'STDERR_FILENO < fd' 
failed
FAIL test-openat-safer (exit status: 134)


The reason is that the test is too strong: It verifies that
"Using a bad directory is okay for absolute paths". But this is not guaranteed
by POSIX [1] (as far as I understand it). Only the Linux man page specifies
this [2].

So let's conditionalize this test.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html
[2] https://linux.die.net/man/2/openat


2018-12-15  Bruno Haible  <address@hidden>

        openat-safer tests: Avoid test failure on NetBSD 8.
        * tests/test-openat-safer.c (main): Execute a Linux specific test only
        on Linux.

diff --git a/tests/test-openat-safer.c b/tests/test-openat-safer.c
index e8977e4..4711a8e 100644
--- a/tests/test-openat-safer.c
+++ b/tests/test-openat-safer.c
@@ -96,11 +96,15 @@ main (void)
           errno = 0;
           ASSERT (openat (dfd, witness "/", O_RDONLY) == -1);
           ASSERT (errno == ENOTDIR || errno == EISDIR || errno == EINVAL);
+#ifdef __linux__
           /* Using a bad directory is okay for absolute paths.  */
           fd = openat (-1, "/dev/null", O_WRONLY);
           ASSERT (STDERR_FILENO < fd);
+#endif
           /* Using a non-directory is wrong for relative paths.  */
           errno = 0;
+          fd = open ("/dev/null", O_RDONLY);
+          ASSERT (STDERR_FILENO < fd);
           ASSERT (openat (fd, ".", O_RDONLY) == -1);
           ASSERT (errno == EBADF || errno == ENOTDIR);
           ASSERT (close (fd) == 0);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]