Skip to content

Commit 54d1358

Browse files
zhufy2019metan-ucw
authored andcommitted
sycalls: select03: Make nfds use the correct value
When running select03 with runltp in /opt/ltp, this case failed as below: select03.c:52: TFAIL: Invalid readfds: select() passed unexpectedly with 0 select03.c:52: TFAIL: Invalid writefds: select() passed unexpectedly with 0 select03.c:52: TFAIL: Invalid exceptfds: select() passed unexpectedly with 0 ltp-pan will leak file descriptors for logfile, failcmdfile and tconfcmdfile, so select() cannot monitor invalid file descriptors for test when nfds is set to 6. Reviewed-by: Yang Xu <[email protected]> Signed-off-by: Feiyu Zhu <[email protected]> Reviewed-by: Cyril Hrubis <[email protected]>
1 parent 0fd3cc4 commit 54d1358

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

testcases/kernel/syscalls/select/select03.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,35 @@ static fd_set readfds_reg, writefds_reg, fds_closed;
1616
static fd_set *preadfds_reg = &readfds_reg, *pwritefds_reg = &writefds_reg;
1717
static fd_set *pfds_closed = &fds_closed, *nullfds = NULL, *faulty_fds;
1818
static int fd_closed, fd[2];
19+
static int negative_nfds = -1, maxfds;
1920
static struct timeval timeout = {.tv_sec = 0, .tv_usec = 100000};
2021

2122
static struct timeval *valid_to = &timeout, *invalid_to;
2223

2324
static struct tcases {
2425
char *name;
25-
int nfds;
26+
int *nfds;
2627
fd_set **readfds;
2728
fd_set **writefds;
2829
fd_set **exceptfds;
2930
struct timeval **timeout;
3031
int exp_errno;
3132
} tests[] = {
32-
{ "Negative nfds", -1, &preadfds_reg, &pwritefds_reg, &nullfds, &valid_to, EINVAL },
33-
{ "Invalid readfds", 6, &pfds_closed, &pwritefds_reg, &nullfds, &valid_to, EBADF },
34-
{ "Invalid writefds", 6, &preadfds_reg, &pfds_closed, &nullfds, &valid_to, EBADF },
35-
{ "Invalid exceptfds", 6, &preadfds_reg, &pwritefds_reg, &pfds_closed, &valid_to, EBADF },
36-
{ "Faulty readfds", 6, &faulty_fds, &pwritefds_reg, &nullfds, &valid_to, EFAULT },
37-
{ "Faulty writefds", 6, &preadfds_reg, &faulty_fds, &nullfds, &valid_to, EFAULT },
38-
{ "Faulty exceptfds", 6, &preadfds_reg, &pwritefds_reg, &faulty_fds, &valid_to, EFAULT },
39-
{ "Faulty timeout", 6, &preadfds_reg, &pwritefds_reg, &nullfds, &invalid_to, EFAULT },
33+
{ "Negative nfds", &negative_nfds, &preadfds_reg, &pwritefds_reg, &nullfds, &valid_to, EINVAL },
34+
{ "Invalid readfds", &maxfds, &pfds_closed, &pwritefds_reg, &nullfds, &valid_to, EBADF },
35+
{ "Invalid writefds", &maxfds, &preadfds_reg, &pfds_closed, &nullfds, &valid_to, EBADF },
36+
{ "Invalid exceptfds", &maxfds, &preadfds_reg, &pwritefds_reg, &pfds_closed, &valid_to, EBADF },
37+
{ "Faulty readfds", &maxfds, &faulty_fds, &pwritefds_reg, &nullfds, &valid_to, EFAULT },
38+
{ "Faulty writefds", &maxfds, &preadfds_reg, &faulty_fds, &nullfds, &valid_to, EFAULT },
39+
{ "Faulty exceptfds", &maxfds, &preadfds_reg, &pwritefds_reg, &faulty_fds, &valid_to, EFAULT },
40+
{ "Faulty timeout", &maxfds, &preadfds_reg, &pwritefds_reg, &nullfds, &invalid_to, EFAULT },
4041
};
4142

4243
static void run(unsigned int n)
4344
{
4445
struct tcases *tc = &tests[n];
4546

46-
TEST(do_select_faulty_to(tc->nfds, *tc->readfds, *tc->writefds,
47+
TEST(do_select_faulty_to(*tc->nfds, *tc->readfds, *tc->writefds,
4748
*tc->exceptfds, *tc->timeout,
4849
tc->timeout == &invalid_to));
4950

@@ -81,6 +82,7 @@ static void setup(void)
8182

8283
SAFE_CLOSE(fd_closed);
8384

85+
maxfds = fd[1] + 1;
8486
faulty_address = tst_get_bad_addr(NULL);
8587
invalid_to = faulty_address;
8688
faulty_fds = faulty_address;

0 commit comments

Comments
 (0)