Skip to content

Commit 50034d4

Browse files
bozutafmetan-ucw
authored andcommitted
syscalls/mq_timed{send|receive}: Add test cases for bad address
This patch introduces test cases for already existing tests for syscalls 'mq_timedsend()' and 'mq_timedreceive()' (mq_timedsend01, mq_timedreceive01). These test cases are for situations when bad addresses are passed for arguments 'msg_ptr' and 'abs_timeout' in which case errno 'EFAULT' is expected to be set. Signed-off-by: Filip Bozuta <[email protected]> Reviewed-by: Cyril Hrubis <[email protected]>
1 parent 135c801 commit 50034d4

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ static int fd, fd_root, fd_nonblock, fd_maxint = INT_MAX - 1, fd_invalid = -1;
1717
#include "mq_timed.h"
1818

1919
static struct tst_ts ts;
20+
static void *bad_addr;
2021

2122
static struct test_case tcase[] = {
2223
{
@@ -123,6 +124,13 @@ static struct test_case tcase[] = {
123124
.ret = -1,
124125
.err = EINTR,
125126
},
127+
{
128+
.fd = &fd,
129+
.len = 16,
130+
.bad_ts_addr = 1,
131+
.ret = -1,
132+
.err = EFAULT,
133+
}
126134
};
127135

128136
static void setup(void)
@@ -132,6 +140,8 @@ static void setup(void)
132140
tst_res(TINFO, "Testing variant: %s", tv->desc);
133141
ts.type = tv->type;
134142

143+
bad_addr = tst_get_bad_addr(NULL);
144+
135145
setup_common();
136146
}
137147

@@ -144,6 +154,7 @@ static void do_test(unsigned int i)
144154
size_t len = MAX_MSGSIZE;
145155
char rmsg[len];
146156
pid_t pid = -1;
157+
void *abs_timeout;
147158

148159
tst_ts_set_sec(&ts, tc->tv_sec);
149160
tst_ts_set_nsec(&ts, tc->tv_nsec);
@@ -164,7 +175,12 @@ static void do_test(unsigned int i)
164175
if (tc->invalid_msg)
165176
len -= 1;
166177

167-
TEST(tv->receive(*tc->fd, rmsg, len, &prio, tst_ts_get(tc->rq)));
178+
if (tc->bad_ts_addr)
179+
abs_timeout = bad_addr;
180+
else
181+
abs_timeout = tst_ts_get(tc->rq);
182+
183+
TEST(tv->receive(*tc->fd, rmsg, len, &prio, abs_timeout));
168184

169185
if (pid > 0)
170186
kill_pid(pid);

testcases/kernel/syscalls/mq_timedsend/mq_timedsend01.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ static int fd, fd_root, fd_nonblock, fd_maxint = INT_MAX - 1, fd_invalid = -1;
1717
#include "mq_timed.h"
1818

1919
static struct tst_ts ts;
20+
static void *bad_addr;
2021

2122
static struct test_case tcase[] = {
2223
{
@@ -129,6 +130,20 @@ static struct test_case tcase[] = {
129130
.ret = -1,
130131
.err = EINTR,
131132
},
133+
{
134+
.fd = &fd,
135+
.len = 16,
136+
.bad_msg_addr = 1,
137+
.ret = -1,
138+
.err = EFAULT,
139+
},
140+
{
141+
.fd = &fd,
142+
.len = 16,
143+
.bad_ts_addr = 1,
144+
.ret = -1,
145+
.err = EFAULT,
146+
}
132147
};
133148

134149
static void setup(void)
@@ -138,6 +153,8 @@ static void setup(void)
138153
tst_res(TINFO, "Testing variant: %s", tv->desc);
139154
ts.type = tv->type;
140155

156+
bad_addr = tst_get_bad_addr(cleanup_common);
157+
141158
setup_common();
142159
}
143160

@@ -150,6 +167,7 @@ static void do_test(unsigned int i)
150167
size_t len = MAX_MSGSIZE;
151168
char rmsg[len];
152169
pid_t pid = -1;
170+
void *msg_ptr, *abs_timeout;
153171

154172
tst_ts_set_sec(&ts, tc->tv_sec);
155173
tst_ts_set_nsec(&ts, tc->tv_nsec);
@@ -168,7 +186,17 @@ static void do_test(unsigned int i)
168186
}
169187
}
170188

171-
TEST(tv->send(*tc->fd, smsg, tc->len, tc->prio, tst_ts_get(tc->rq)));
189+
if (tc->bad_msg_addr)
190+
msg_ptr = bad_addr;
191+
else
192+
msg_ptr = smsg;
193+
194+
if (tc->bad_ts_addr)
195+
abs_timeout = bad_addr;
196+
else
197+
abs_timeout = tst_ts_get(tc->rq);
198+
199+
TEST(tv->send(*tc->fd, msg_ptr, tc->len, tc->prio, abs_timeout));
172200

173201
if (pid > 0)
174202
kill_pid(pid);
@@ -179,7 +207,7 @@ static void do_test(unsigned int i)
179207
"mq_timedsend() failed unexpectedly, expected %s",
180208
tst_strerrno(tc->err));
181209
else
182-
tst_res(TPASS | TTERRNO, "mq_timedreceive() failed expectedly");
210+
tst_res(TPASS | TTERRNO, "mq_timedsend() failed expectedly");
183211

184212
if (*tc->fd == fd)
185213
cleanup_queue(fd);

testcases/kernel/syscalls/utils/mq_timed.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ struct test_case {
4141
int send;
4242
int signal;
4343
int timeout;
44+
int bad_msg_addr;
45+
int bad_ts_addr;
4446
int ret;
4547
int err;
4648
};

0 commit comments

Comments
 (0)