aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndy Pan <i@andypan.me>2024-09-10 02:22:15 +0800
committerGitHub <noreply@github.com>2024-09-09 20:22:15 +0200
commit44e61dab7effb739f543b8b4eee43f577bf2db49 (patch)
tree1c997aef8b6cba807bdd742c69f1a127eea9ffdf /test
parent0a00e80c3686b93eccb9a801954e86bd7d7fe6ab (diff)
downloadlibuv-44e61dab7effb739f543b8b4eee43f577bf2db49.tar.gz
libuv-44e61dab7effb739f543b8b4eee43f577bf2db49.zip
kqueue: disallow ill-suited file descriptor kinds (#4513)
Follows up on https://github.com/libuv/libuv/pull/659. Signed-off-by: Andy Pan <i@andypan.me>
Diffstat (limited to 'test')
-rw-r--r--test/test-poll.c57
1 files changed, 45 insertions, 12 deletions
diff --git a/test/test-poll.c b/test/test-poll.c
index fcd644f2..5161de25 100644
--- a/test/test-poll.c
+++ b/test/test-poll.c
@@ -626,26 +626,59 @@ TEST_IMPL(poll_unidirectional) {
/* Windows won't let you open a directory so we open a file instead.
- * OS X lets you poll a file so open the $PWD instead. Both fail
- * on Linux so it doesn't matter which one we pick. Both succeed
- * on FreeBSD, Solaris and AIX so skip the test on those platforms.
+ * OS X lets you poll a file so open the $PWD instead. Both fail
+ * on Linux so it doesn't matter which one we pick. Both succeed
+ * on Solaris and AIX so skip the test on those platforms.
+ * On *BSD/Darwin, we disallow polling of regular files, directories.
+ * In addition to regular files, we also disallow FIFOs on Darwin.
*/
+#ifdef __APPLE__
+#define TEST_POLL_FIFO_PATH "/tmp/uv-test-poll-fifo"
+#endif
TEST_IMPL(poll_bad_fdtype) {
-#if !defined(__DragonFly__) && !defined(__FreeBSD__) && !defined(__sun) && \
+#if !defined(__sun) && \
!defined(_AIX) && !defined(__MVS__) && \
- !defined(__OpenBSD__) && !defined(__CYGWIN__) && !defined(__MSYS__) && \
- !defined(__NetBSD__)
+ !defined(__CYGWIN__) && !defined(__MSYS__)
uv_poll_t poll_handle;
- int fd;
+ int fd[2];
#if defined(_WIN32)
- fd = _open("test/fixtures/empty_file", UV_FS_O_RDONLY);
+ fd[0] = _open("test/fixtures/empty_file", UV_FS_O_RDONLY);
#else
- fd = open(".", UV_FS_O_RDONLY);
+ fd[0] = open(".", UV_FS_O_RDONLY);
+#endif
+ ASSERT_NE(fd[0], -1);
+ ASSERT_NE(0, uv_poll_init(uv_default_loop(), &poll_handle, fd[0]));
+ ASSERT_OK(close(fd[0]));
+#if defined(__APPLE__) || \
+ defined(__DragonFly__) || \
+ defined(__FreeBSD__) || \
+ defined(__OpenBSD__) || \
+ defined(__NetBSD__)
+ fd[0] = open("test/fixtures/empty_file", UV_FS_O_RDONLY);
+ ASSERT_NE(fd[0], -1);
+ /* Regular files should be banned from kqueue. */
+ ASSERT_NE(0, uv_poll_init(uv_default_loop(), &poll_handle, fd[0]));
+ ASSERT_OK(close(fd[0]));
+#ifdef __APPLE__
+ ASSERT_OK(pipe(fd));
+ /* Pipes should be permitted in kqueue. */
+ ASSERT_EQ(0, uv_poll_init(uv_default_loop(), &poll_handle, fd[0]));
+ ASSERT_OK(close(fd[0]));
+ ASSERT_OK(close(fd[1]));
+
+ ASSERT_OK(mkfifo(TEST_POLL_FIFO_PATH, 0600));
+ fd[0] = open(TEST_POLL_FIFO_PATH, O_RDONLY | O_NONBLOCK);
+ ASSERT_NE(fd[0], -1);
+ fd[1] = open(TEST_POLL_FIFO_PATH, O_WRONLY | O_NONBLOCK);
+ ASSERT_NE(fd[1], -1);
+ /* FIFOs should be banned from kqueue. */
+ ASSERT_NE(0, uv_poll_init(uv_default_loop(), &poll_handle, fd[0]));
+ ASSERT_OK(close(fd[0]));
+ ASSERT_OK(close(fd[1]));
+ unlink(TEST_POLL_FIFO_PATH);
+#endif
#endif
- ASSERT_NE(fd, -1);
- ASSERT_NE(0, uv_poll_init(uv_default_loop(), &poll_handle, fd));
- ASSERT_OK(close(fd));
#endif
MAKE_VALGRIND_HAPPY(uv_default_loop());