Skip to content

Commit d44707d

Browse files
committed
Fix dumping of recvmmsg syscall in case of short read
* net.c (dumpiov_in_mmsghdr): Call dumpiov_upto instead of dumpiov, pass data size limit to dumpiov_upto. * NEWS: Mention this fix. * tests/mmsg.c (main): Update.
1 parent 93c9d1c commit d44707d

File tree

3 files changed

+112
-64
lines changed

3 files changed

+112
-64
lines changed

NEWS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Noteworthy changes in release ?.?? (????-??-??)
1414
* Fixed decoding of syscalls unknown to the kernel on s390/s390x.
1515
(addresses Debian bug #485979 and Fedora bug #1298294).
1616
* Fixed decoding and dumping of readv syscall in case of short read.
17-
* Fixed dumping of recvmsg syscall in case of short read.
17+
* Fixed dumping of recvmsg and recvmmsg syscalls in case of short read.
1818

1919
Noteworthy changes in release 4.11 (2015-12-21)
2020
===============================================

net.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,8 @@ dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
763763
if (extractmmsghdr(tcp, addr, i, &mmsg)) {
764764
tprintf(" = %lu buffers in vector %u\n",
765765
(unsigned long)mmsg.msg_hdr.msg_iovlen, i);
766-
dumpiov(tcp, mmsg.msg_hdr.msg_iovlen,
767-
(long)mmsg.msg_hdr.msg_iov);
766+
dumpiov_upto(tcp, mmsg.msg_hdr.msg_iovlen,
767+
(long)mmsg.msg_hdr.msg_iov, mmsg.msg_len);
768768
}
769769
}
770770
}

tests/mmsg.c

Lines changed: 109 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -87,102 +87,150 @@ main(void)
8787
{
8888
tprintf("%s", "");
8989

90-
const int R = 0, W = 1;
91-
int sv[2];
92-
if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sv))
90+
int fds[2];
91+
if (socketpair(AF_UNIX, SOCK_DGRAM, 0, fds))
9392
perror_msg_and_skip("socketpair");
94-
assert(R == sv[0]);
95-
assert(W == sv[1]);
93+
assert(0 == fds[0]);
94+
assert(1 == fds[1]);
9695

97-
static const char one[] = "one";
98-
static const char two[] = "two";
99-
static const char three[] = "three";
100-
static const char ascii_one[] = "6f 6e 65";
101-
static const char ascii_two[] = "74 77 6f";
102-
static const char ascii_three[] = "74 68 72 65 65";
96+
static const char w0_c[] = "012";
97+
const char *w0_d = hexdump_strdup(w0_c);
98+
void *w0 = tail_memdup(w0_c, LENGTH_OF(w0_c));
10399

104-
void *copy_one = tail_memdup(one, LENGTH_OF(one));
105-
void *copy_two = tail_memdup(two, LENGTH_OF(two));
106-
void *copy_three = tail_memdup(three, LENGTH_OF(three));
100+
static const char w1_c[] = "34567";
101+
const char *w1_d = hexdump_strdup(w1_c);
102+
void *w1 = tail_memdup(w1_c, LENGTH_OF(w1_c));
107103

108-
struct iovec iov[] = {
104+
static const char w2_c[] = "89abcde";
105+
const char *w2_d = hexdump_strdup(w2_c);
106+
void *w2 = tail_memdup(w2_c, LENGTH_OF(w2_c));
107+
108+
const struct iovec w0_iov_[] = {
109109
{
110-
.iov_base = copy_one,
111-
.iov_len = LENGTH_OF(one)
112-
}, {
113-
.iov_base = copy_two,
114-
.iov_len = LENGTH_OF(two)
110+
.iov_base = w0,
111+
.iov_len = LENGTH_OF(w0_c)
115112
}, {
116-
.iov_base = copy_three,
117-
.iov_len = LENGTH_OF(three)
113+
.iov_base = w1,
114+
.iov_len = LENGTH_OF(w1_c)
118115
}
119116
};
120-
struct iovec *copy_iov = tail_memdup(iov, sizeof(iov));
117+
struct iovec *w0_iov = tail_memdup(w0_iov_, sizeof(w0_iov_));
121118

122-
struct mmsghdr mmh[] = {
119+
const struct iovec w1_iov_[] = {
120+
{
121+
.iov_base = w2,
122+
.iov_len = LENGTH_OF(w2_c)
123+
}
124+
};
125+
struct iovec *w1_iov = tail_memdup(w1_iov_, sizeof(w1_iov_));
126+
127+
const struct mmsghdr w_mmh_[] = {
123128
{
124129
.msg_hdr = {
125-
.msg_iov = copy_iov + 0,
126-
.msg_iovlen = 2,
130+
.msg_iov = w0_iov,
131+
.msg_iovlen = ARRAY_SIZE(w0_iov_),
127132
}
128133
}, {
129134
.msg_hdr = {
130-
.msg_iov = copy_iov + 2,
131-
.msg_iovlen = 1,
135+
.msg_iov = w1_iov,
136+
.msg_iovlen = ARRAY_SIZE(w1_iov_),
132137
}
133138
}
134139
};
135-
void *copy_mmh = tail_memdup(mmh, sizeof(mmh));
136-
# define n_mmh ((unsigned int) (sizeof(mmh)/sizeof(mmh[0])))
140+
void *w_mmh = tail_memdup(w_mmh_, sizeof(w_mmh_));
141+
const unsigned int n_w_mmh = ARRAY_SIZE(w_mmh_);
137142

138-
int r = send_mmsg(W, copy_mmh, n_mmh, MSG_DONTROUTE | MSG_NOSIGNAL);
143+
int r = send_mmsg(1, w_mmh, n_w_mmh, MSG_DONTROUTE | MSG_NOSIGNAL);
139144
if (r < 0 && errno == ENOSYS)
140145
perror_msg_and_skip("sendmmsg");
141-
assert(r == (int) n_mmh);
142-
assert(close(W) == 0);
143-
tprintf("sendmmsg(%d, {{{msg_name(0)=NULL, msg_iov(%u)=[{\"%s\", %u}"
146+
assert(r == (int) n_w_mmh);
147+
assert(close(1) == 0);
148+
tprintf("sendmmsg(1, {{{msg_name(0)=NULL, msg_iov(%u)=[{\"%s\", %u}"
144149
", {\"%s\", %u}], msg_controllen=0, msg_flags=0}, %u}"
145150
", {{msg_name(0)=NULL, msg_iov(%u)=[{\"%s\", %u}]"
146151
", msg_controllen=0, msg_flags=0}, %u}}, %u"
147152
", MSG_DONTROUTE|MSG_NOSIGNAL) = %d\n"
148153
" = %u buffers in vector 0\n"
149154
" * %u bytes in buffer 0\n"
150-
" | 00000 %-48s %-16s |\n"
155+
" | 00000 %-49s %-16s |\n"
151156
" * %u bytes in buffer 1\n"
152-
" | 00000 %-48s %-16s |\n"
157+
" | 00000 %-49s %-16s |\n"
153158
" = %u buffers in vector 1\n"
154159
" * %u bytes in buffer 0\n"
155-
" | 00000 %-48s %-16s |\n",
156-
W, 2, one, LENGTH_OF(one), two, LENGTH_OF(two),
157-
LENGTH_OF(one) + LENGTH_OF(two),
158-
1, three, LENGTH_OF(three), LENGTH_OF(three),
159-
n_mmh, r,
160-
2, LENGTH_OF(one), ascii_one, one,
161-
LENGTH_OF(two), ascii_two, two,
162-
1, LENGTH_OF(three), ascii_three, three);
163-
164-
assert(recv_mmsg(R, copy_mmh, n_mmh, MSG_DONTWAIT, NULL) == (int) n_mmh);
165-
assert(close(R) == 0);
166-
tprintf("recvmmsg(%d, {{{msg_name(0)=NULL, msg_iov(%u)=[{\"%s\", %u}"
167-
", {\"%s\", %u}], msg_controllen=0, msg_flags=0}, %u}"
168-
", {{msg_name(0)=NULL, msg_iov(%u)=[{\"%s\", %u}]"
160+
" | 00000 %-49s %-16s |\n",
161+
ARRAY_SIZE(w0_iov_), w0_c, LENGTH_OF(w0_c),
162+
w1_c, LENGTH_OF(w1_c),
163+
LENGTH_OF(w0_c) + LENGTH_OF(w1_c),
164+
ARRAY_SIZE(w1_iov_), w2_c, LENGTH_OF(w2_c), LENGTH_OF(w2_c),
165+
n_w_mmh, r,
166+
ARRAY_SIZE(w0_iov_), LENGTH_OF(w0_c), w0_d, w0_c,
167+
LENGTH_OF(w1_c), w1_d, w1_c,
168+
ARRAY_SIZE(w1_iov_), LENGTH_OF(w2_c), w2_d, w2_c);
169+
170+
const unsigned int w_len =
171+
LENGTH_OF(w0_c) + LENGTH_OF(w1_c) + LENGTH_OF(w2_c);
172+
const unsigned int r_len = (w_len + 1) / 2;
173+
void *r0 = tail_alloc(r_len);
174+
void *r1 = tail_alloc(r_len);
175+
void *r2 = tail_alloc(r_len);
176+
const struct iovec r0_iov_[] = {
177+
{
178+
.iov_base = r0,
179+
.iov_len = r_len
180+
}
181+
};
182+
struct iovec *r0_iov = tail_memdup(r0_iov_, sizeof(r0_iov_));
183+
const struct iovec r1_iov_[] = {
184+
{
185+
.iov_base = r1,
186+
.iov_len = r_len
187+
},
188+
{
189+
.iov_base = r2,
190+
.iov_len = r_len
191+
}
192+
};
193+
struct iovec *r1_iov = tail_memdup(r1_iov_, sizeof(r1_iov_));
194+
195+
const struct mmsghdr r_mmh_[] = {
196+
{
197+
.msg_hdr = {
198+
.msg_iov = r0_iov,
199+
.msg_iovlen = ARRAY_SIZE(r0_iov_),
200+
}
201+
}, {
202+
.msg_hdr = {
203+
.msg_iov = r1_iov,
204+
.msg_iovlen = ARRAY_SIZE(r1_iov_),
205+
}
206+
}
207+
};
208+
void *r_mmh = tail_memdup(r_mmh_, sizeof(r_mmh_));
209+
const unsigned int n_r_mmh = ARRAY_SIZE(r_mmh_);
210+
211+
static const char r0_c[] = "01234567";
212+
const char *r0_d = hexdump_strdup(r0_c);
213+
static const char r1_c[] = "89abcde";
214+
const char *r1_d = hexdump_strdup(r1_c);
215+
216+
assert(recv_mmsg(0, r_mmh, n_r_mmh, MSG_DONTWAIT, NULL) == (int) n_r_mmh);
217+
assert(close(0) == 0);
218+
tprintf("recvmmsg(0, {{{msg_name(0)=NULL, msg_iov(%u)=[{\"%s\", %u}]"
219+
", msg_controllen=0, msg_flags=0}, %u}"
220+
", {{msg_name(0)=NULL, msg_iov(%u)=[{\"%s\", %u}, {\"\", %u}]"
169221
", msg_controllen=0, msg_flags=0}, %u}}, %u"
170222
", MSG_DONTWAIT, NULL) = %d (left NULL)\n"
171223
" = %u buffers in vector 0\n"
172224
" * %u bytes in buffer 0\n"
173-
" | 00000 %-48s %-16s |\n"
174-
" * %u bytes in buffer 1\n"
175-
" | 00000 %-48s %-16s |\n"
225+
" | 00000 %-49s %-16s |\n"
176226
" = %u buffers in vector 1\n"
177227
" * %u bytes in buffer 0\n"
178-
" | 00000 %-48s %-16s |\n",
179-
R, 2, one, LENGTH_OF(one), two, LENGTH_OF(two),
180-
LENGTH_OF(one) + LENGTH_OF(two),
181-
1, three, LENGTH_OF(three), LENGTH_OF(three),
182-
n_mmh, r,
183-
2, LENGTH_OF(one), ascii_one, one,
184-
LENGTH_OF(two), ascii_two, two,
185-
1, LENGTH_OF(three), ascii_three, three);
228+
" | 00000 %-49s %-16s |\n",
229+
ARRAY_SIZE(r0_iov_), r0_c, r_len, LENGTH_OF(r0_c),
230+
ARRAY_SIZE(r1_iov_), r1_c, r_len, r_len, LENGTH_OF(r1_c),
231+
n_r_mmh, r,
232+
ARRAY_SIZE(r0_iov_), LENGTH_OF(r0_c), r0_d, r0_c,
233+
ARRAY_SIZE(r1_iov_), LENGTH_OF(r1_c), r1_d, r1_c);
186234

187235
tprintf("+++ exited with 0 +++\n");
188236
return 0;

0 commit comments

Comments
 (0)