[PATCH v3 3/7] tests: check decoding of netlink protocol

Dmitry V. Levin ldv at altlinux.org
Thu Jun 16 10:40:18 UTC 2016


On Wed, Jun 15, 2016 at 12:43:01PM +0000, Fabien Siron wrote:
[...]
> +static void
> +send_query(const int fd, const unsigned int pid_magic)
> +{
> +	struct {
> +		struct nlmsghdr nlh;
> +		char magic[4];
> +	} req = {
> +		.nlh = {
> +			.nlmsg_len = sizeof(req),
> +			.nlmsg_type = NLMSG_NOOP,
> +			.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST
> +		},
> +		.magic = "abcd"
> +	};
> +
> +	if (sendto(fd, &req, sizeof(req), MSG_DONTWAIT, NULL, 0) !=
> +	    (unsigned) sizeof(req))
> +		perror_msg_and_skip("sendto");
> +
> +	printf("sendto(%d<NETLINK:[SOCK_DIAG:%u]>, {{len=%u, type=NLMSG_NOOP, "
> +	       "flags=NLM_F_REQUEST|0x%x, seq=0, pid=0}, \"abcd\"}, %u, "
> +	       "MSG_DONTWAIT, NULL, 0) = %u\n",
> +	       fd, pid_magic, (unsigned) sizeof(req), NLM_F_DUMP,
> +	       (unsigned) sizeof(req), (unsigned) sizeof(req));

I'd also add coverage for the following corner cases when
+ data length equals to sizeof(struct nlmsghdr);
+ data length is less than sizeof(struct nlmsghdr);
+ data length is enough but data points to unmapped memory.

Otherwise looks OK.


-- 
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/20160616/ded966c8/attachment.bin>


More information about the Strace-devel mailing list