From: Dmitry V. Levin Date: Fri, 4 Aug 2017 19:08:27 +0000 (+0000) Subject: tests: fix unaligned access in nlattr.test X-Git-Tag: v4.19~182 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=17f095a9457c4a03faefddcf90e67ba5792e09af;p=strace tests: fix unaligned access in nlattr.test * tests/nlattr.c (test_nlattr): Use SET_STRUCT to initialize potentially unaligned struct nlattr. --- diff --git a/tests/nlattr.c b/tests/nlattr.c index f7da752d..a2d59d42 100644 --- a/tests/nlattr.c +++ b/tests/nlattr.c @@ -144,10 +144,10 @@ test_nlattr(const int fd) msg = tail_memdup(&c_msg, msg_len); memcpy(&msg->nlh.nlmsg_len, &msg_len, sizeof(msg_len)); nla = NLMSG_ATTR(msg, sizeof(msg->udm)); - *nla = (struct nlattr) { + SET_STRUCT(struct nlattr, nla, .nla_len = NLA_HDRLEN, .nla_type = UNIX_DIAG_NAME - }; + ); memcpy(nla + 1, "12", 2); rc = sendto(fd, msg, msg_len, MSG_DONTWAIT, NULL, 0); printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY" @@ -156,17 +156,17 @@ test_nlattr(const int fd) ", udiag_ino=0, udiag_cookie=[0, 0]}, [{nla_len=%u" ", nla_type=UNIX_DIAG_NAME}, \"\\x31\\x32\"]}, %u" ", MSG_DONTWAIT, NULL, 0) = %s\n", - fd, msg_len, nla->nla_len, msg_len, sprintrc(rc)); + fd, msg_len, NLA_HDRLEN, msg_len, sprintrc(rc)); /* print one struct nlattr and short read of second struct nlattr */ msg_len = NLMSG_SPACE(sizeof(msg->udm)) + NLA_HDRLEN * 2; msg = tail_memdup(&c_msg, msg_len - 1); memcpy(&msg->nlh.nlmsg_len, &msg_len, sizeof(msg_len)); nla = NLMSG_ATTR(msg, sizeof(msg->udm)); - *nla = (struct nlattr) { + SET_STRUCT(struct nlattr, nla, .nla_len = NLA_HDRLEN, .nla_type = UNIX_DIAG_NAME - }; + ); rc = sendto(fd, msg, msg_len, MSG_DONTWAIT, NULL, 0); printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY" ", flags=NLM_F_DUMP, seq=0, pid=0}, {udiag_family=AF_UNIX" @@ -174,7 +174,7 @@ test_nlattr(const int fd) ", udiag_ino=0, udiag_cookie=[0, 0]}, [{nla_len=%u" ", nla_type=UNIX_DIAG_NAME}, %p]}, %u" ", MSG_DONTWAIT, NULL, 0) = %s\n", - fd, msg_len, nla->nla_len, nla + 1, msg_len, sprintrc(rc)); + fd, msg_len, NLA_HDRLEN, nla + 1, msg_len, sprintrc(rc)); /* print two struct nlattr */ msg_len = NLMSG_SPACE(sizeof(msg->udm)) + NLA_HDRLEN * 2;