[PATCH 4/4] tests: check decoding of nlmsgerr attributes

JingPiao Chen chenjingpiao at gmail.com
Wed Jul 19 02:15:41 UTC 2017


On Wed, Jul 19, 2017 at 12:47:59AM +0300, Dmitry V. Levin wrote:
> On Mon, Jul 17, 2017 at 11:07:46PM +0800, JingPiao Chen wrote:
> > * tests/nlattr_nlmsgerr.c: New file.
> > * tests/gen_tests.in (nlattr_nlmsgerr): New entry.
> > * tests/pure_executables.list: Add nlattr_nlmsgerr.
> > * tests/.gitignore: Likewise.
> [...]
> > +int
> > +main(void)
> > +{
> > + skip_if_unavailable("/proc/self/fd/");
> > +
> > + const int fd = create_nl_socket(NETLINK_SOCK_DIAG);
> > + const unsigned int hdrlen = sizeof(struct nlmsgerr);
> > + void *const nlh0 = tail_alloc(NLMSG_SPACE(hdrlen));
> > +
> > + static char pattern[4096];
> > + fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
> > +
> > + static const uint8_t cookie[] = { 0xab, 0xfe };
> > + TEST_NLATTR(fd, nlh0, hdrlen,
> > +    init_nlmsgerr, print_nlmsgerr,
> > +    NLMSGERR_ATTR_COOKIE,
> > +    sizeof(cookie), cookie, sizeof(cookie),
> > +    printf("[%u, %u]", cookie[0], cookie[1]);
> > +    printf("}"));
> > +
> > + printf("+++ exited with 0 +++\n");
> > + return 0;
> > +}
>
> Note that pattern is initialized but never used here.
> Shouldn't TEST_NLATTR_ARRAY be used here instead of TEST_NLATTR?

Can not. Because sizeof(cookie[0]) == 1, plen == 0, test will output "", but
strace do not output "". And this header different from other header,
attributes is in inner:

struct nlmsgerr {
error;
nlmsghdr;
[...];
[attributes];
}

We need print brace after print attributes.

--
JingPiao Chen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20170719/2e88ade3/attachment.html>


More information about the Strace-devel mailing list