From 2f58d08d66740bfe7fe5c581027965da04afecd7 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Tue, 2 Oct 2012 19:38:24 -0600 Subject: [PATCH] select: enhance test Make sure the test is not picking up stale errno values, and add a test for nfds validation. * tests/test-select.h (do_select_bad_nfd_nowait, test_bad_nfd): New functions. (test_function): Enhance test. (do_select_bad_fd): Avoid any stale errno values. --- ChangeLog | 6 ++++++ tests/test-select.h | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/ChangeLog b/ChangeLog index c27db0d79..38a0f3fa6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2012-10-02 Eric Blake + select: enhance test + * tests/test-select.h (do_select_bad_nfd_nowait, test_bad_nfd): + New functions. + (test_function): Enhance test. + (do_select_bad_fd): Avoid any stale errno values. + ptsname: reject invalid file descriptors http://www.austingroupbugs.net/view.php?id=503 * m4/ptsname.m4 (gl_FUNC_PTSNAME): Probe for FreeBSD bug. diff --git a/tests/test-select.h b/tests/test-select.h index af0e38cf0..e9cb7d04f 100644 --- a/tests/test-select.h +++ b/tests/test-select.h @@ -227,6 +227,29 @@ test_tty (select_fn my_select) #endif +static int +do_select_bad_nfd_nowait (int nfd, select_fn my_select) +{ + struct timeval tv0; + tv0.tv_sec = 0; + tv0.tv_usec = 0; + errno = 0; + return my_select (nfd, NULL, NULL, NULL, &tv0); +} + +static void +test_bad_nfd (select_fn my_select) +{ + if (do_select_bad_nfd_nowait (-1, my_select) != -1 || errno != EINVAL) + failed ("invalid errno after negative nfds"); + /* Can't test FD_SETSIZE + 1 for EINVAL, since some systems allow + dynamically larger set size by redefining FD_SETSIZE anywhere up + to the actual maximum fd. */ + /* if (do_select_bad_nfd_nowait (FD_SETSIZE + 1, my_select) != -1 */ + /* || errno != EINVAL) */ + /* failed ("invalid errno after bogus nfds"); */ +} + /* Test select(2) on invalid file descriptors. */ static int @@ -243,6 +266,7 @@ do_select_bad_fd (int fd, int ev, struct timeval *timeout, select_fn my_select) FD_SET (fd, &wfds); if (ev & SEL_EXC) FD_SET (fd, &xfds); + errno = 0; return my_select (fd + 1, &rfds, &wfds, &xfds, timeout); /* In this case, when fd is invalid, on some platforms, the bit for fd is left alone in the fd_set, whereas on other platforms it is cleared. @@ -426,6 +450,7 @@ test_function (select_fn my_select) test (test_tty, "TTY", my_select); #endif + result += test (test_bad_nfd, my_select, "Invalid nfd test"); result += test (test_bad_fd, my_select, "Invalid fd test"); result += test (test_connect_first, my_select, "Unconnected socket test"); result += test (test_socket_pair, my_select, "Connected sockets test"); -- 2.11.0