[PATCH] tests: check decoding of NETLINK_SOCK_DIAG AF_UNIX messages
Dmitry V. Levin
ldv at altlinux.org
Tue Jun 13 18:18:37 UTC 2017
On Tue, Jun 13, 2017 at 07:10:13PM +0300, Dmitry V. Levin wrote:
> On Tue, Jun 13, 2017 at 07:04:21PM +0800, JingPiao Chen wrote:
> > +static void
> > +test_unix_diag_req(const int fd)
> > +{
> > ...
> > + /* short read of unix_diag_req */
> > + nlh = nlh0 - (sizeof(*req) - 1);
> > + memmove(nlh, nlh0 - sizeof(*req), NLMSG_HDRLEN + sizeof(*req) - 1);
> > +
> > + rc = sendto(fd, nlh, NLMSG_HDRLEN + sizeof(*req), MSG_DONTWAIT,
> > + NULL, 0);
> > +
> > + printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
> > + ", flags=NLM_F_REQUEST, seq=0, pid=0}, {family=AF_UNIX, %p}}"
> > + ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
> > + fd, NLMSG_HDRLEN + (unsigned int) sizeof(*req),
> > + NLMSG_DATA(nlh) + 1,
> > + NLMSG_HDRLEN + (unsigned int) sizeof(*req),
> > + sprintrc(rc));
> > +}
> >
> > When (sizeof(*req) - 1 - sizeof(*family) > DEFAULT_STRLEN), the test will
> > fail.
>
> Why? In this part of the test strace is expected to print a pointer,
> not a string, so it shouldn't be affected by DEFAULT_STRLEN.
>
> > I replace sizeof(*req) - 1 with sizeof(*family).
> >
> > nlh = nlh0 - sizeof(*family);
> > memmove(nlh, nlh0 - sizeof(*req), NLMSG_HDRLEN + sizeof(*family));
My idea is to specify a memory area that is exactly 1 byte less than
necessary, this way we can test corner cases better.
--
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20170613/7574f66a/attachment.bin>
More information about the Strace-devel
mailing list