[PATCH v2 3/7] tests: check decoding of netlink protocol
Dmitry V. Levin
ldv at altlinux.org
Tue Jun 14 12:03:47 UTC 2016
On Mon, Jun 13, 2016 at 02:37:23PM +0000, Fabien Siron wrote:
[...]
> +static void
> +send_query(const int fd)
> +{
> + struct {
> + struct nlmsghdr nlh;
> + char magic[4];
> + } req = {
> + .nlh = {
> + .nlmsg_len = sizeof(req),
> + .nlmsg_type = SOCK_DIAG_BY_FAMILY,
> + .nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST
> + },
> + .magic = "abcd"
> + };
> +
> + if (sendto(fd, &req, sizeof(req), MSG_DONTWAIT, NULL, 0) <= 0)
> + perror_msg_and_skip("sendto");
Why <= 0? The next statement assumes == (unsigned) sizeof(req).
> +
> + printf("sendto(%d, {{len=%u, type=20, flags=NLM_F_REQUEST|0x300, "
> + "seq=0, pid=0}, \"abcd\"}, 20, MSG_DONTWAIT, NULL, 0) = %u\n",
> + fd, (unsigned) sizeof(req), (unsigned) sizeof(req));
Please do not encode values of constants into output strings verbatim.
--
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20160614/70aae14d/attachment.bin>
More information about the Strace-devel
mailing list