[PATCH] netlink: decode NLMSG_DONE message

Dmitry V. Levin ldv at altlinux.org
Fri Jun 2 22:36:02 UTC 2017


On Fri, Jun 02, 2017 at 06:25:28PM +0300, Dmitry V. Levin wrote:
[...]
> I suggest implementing a default decoder of NLMSG_DONE messages that
> would print the integer in case of len == sizeof(int) and fall back
> to  printstrn for other lengths.
> 
> When protocol specific netlink decoders are added, they could either
> decode NLMSG_DONE themselves (and return true) or just return false to
> fall back to default decoder.

To facilitate this approach, I'm going to apply the following change
to payload decoders:

--- a/netlink.c
+++ b/netlink.c
@@ -83,6 +83,11 @@ decode_nlmsgerr(struct tcb *const tcp,
 {
 	struct nlmsgerr err;
 
+	if (len < sizeof(err.error)) {
+		printstrn(tcp, addr, len);
+		return;
+	}
+
 	if (umove_or_printaddr(tcp, addr, &err.error))
 		return;
 
@@ -112,11 +117,12 @@ decode_payload(struct tcb *const tcp,
 	       const kernel_ulong_t addr,
 	       const kernel_ulong_t len)
 {
-	if (nlmsghdr->nlmsg_type == NLMSG_ERROR && len >= sizeof(int)) {
+	if (nlmsghdr->nlmsg_type == NLMSG_ERROR) {
 		decode_nlmsgerr(tcp, addr, len);
-	} else {
-		printstrn(tcp, addr, len);
+		return;
 	}
+
+	printstrn(tcp, addr, len);
 }
 
 static void


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20170603/40cd8be9/attachment.bin>


More information about the Strace-devel mailing list