[PATCH] tests: check decoding of NETLINK_SOCK_DIAG AF_UNIX messages

JingPiao Chen chenjingpiao at gmail.com
Tue Jun 13 11:04:21 UTC 2017


+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.
I replace sizeof(*req) - 1 with sizeof(*family).

nlh = nlh0 - sizeof(*family);
memmove(nlh, nlh0 - sizeof(*req), NLMSG_HDRLEN + sizeof(*family));

+static void
+test_unix_diag_msg(const int fd)
+{
...
+ /* short read of unix_diag_msg */
+ nlh = nlh0 - (sizeof(*msg) - 1);
+ memmove(nlh, nlh0 - sizeof(*msg), NLMSG_HDRLEN + sizeof(*msg) - 1);
+
+ rc = sendto(fd, nlh, NLMSG_HDRLEN + sizeof(*msg), MSG_DONTWAIT,
+    NULL, 0);
+
+ printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
+       ", flags=NLM_F_DUMP, seq=0, pid=0}, {family=AF_UNIX, %p}}"
+       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+       fd, NLMSG_HDRLEN + (unsigned int) sizeof(*msg),
+       NLMSG_DATA(nlh) + 1,
+       NLMSG_HDRLEN + (unsigned int) sizeof(*msg),
+       sprintrc(rc));
+}

Likewise.

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


More information about the Strace-devel mailing list