TEST_NLATTR_OBJECT and TEST_NLATTR_ARRAY fault when sizeof(obj) - 1 > DEFAULT_STRLEN

Dmitry V. Levin ldv at altlinux.org
Sun Jul 2 22:22:52 UTC 2017


On Sun, Jul 02, 2017 at 12:12:54PM +0800, JingPiao Chen wrote:
> when sizeof(obj) - 1 > DEFAULT_STRLEN, we print all string,
> but strace print "STR"..., so the test fault.
> This appear when I test packet_diag_msg PACKET_DIAG_MCLIST.

Does this patch solve it?

--- a/tests/test_nlattr.h
+++ b/tests/test_nlattr.h
@@ -99,20 +99,19 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type)
 			   init_msg_, print_msg_,			\
 			   nla_type_, pattern_, obj_, ...)		\
 	do {								\
+		const size_t plen = sizeof(obj_) - 1 > DEFAULT_STRLEN	\
+			? DEFAULT_STRLEN : sizeof(obj_) - 1;		\
 		/* len < sizeof(obj_) */				\
 		TEST_NLATTR_((fd_), (nlh0_), (hdrlen_),			\
 			(init_msg_), (print_msg_),			\
 			(nla_type_), #nla_type_,			\
-			sizeof(obj_) - 1,				\
-			(pattern_), sizeof(obj_) - 1,			\
-			printf("\"%.*s\"",				\
-			(int) sizeof(obj_) - 1,	(pattern_)));		\
+			plen, (pattern_), plen,				\
+			printf("\"%.*s\"", (int) plen, (pattern_)));	\
 		/* short read of sizeof(obj_) */			\
 		TEST_NLATTR_((fd_), (nlh0_), (hdrlen_),			\
 			(init_msg_), (print_msg_),			\
 			(nla_type_), #nla_type_,			\
-			sizeof(obj_),					\
-			(pattern_), sizeof(obj_) - 1,			\
+			sizeof(obj_), (pattern_), plen,			\
 			printf("%p",					\
 			       RTA_DATA(NLMSG_ATTR(nlh, (hdrlen_)))));	\
 		/* sizeof(obj_) */					\
@@ -128,15 +127,15 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type)
 			  init_msg_, print_msg_,			\
 			  nla_type_, pattern_, obj_, print_elem_)	\
 	do {								\
+		const size_t plen =					\
+			sizeof((obj_)[0]) - 1 > DEFAULT_STRLEN		\
+			? DEFAULT_STRLEN : sizeof((obj_)[0]) - 1;	\
 		/* len < sizeof((obj_)[0]) */				\
 		TEST_NLATTR_((fd_), (nlh0_), (hdrlen_),			\
 			(init_msg_), (print_msg_),			\
 			(nla_type_), #nla_type_,			\
-			sizeof((obj_)[0]) - 1,				\
-			(pattern_), sizeof((obj_)[0]) - 1,		\
-			printf("\"%.*s\"",				\
-			       (int) sizeof((obj_)[0]) - 1,		\
-			       (pattern_)));				\
+			plen, (pattern_), plen,				\
+			printf("\"%.*s\"", (int) plen, (pattern_)));	\
 		/* sizeof((obj_)[0]) < len < sizeof(obj_) */		\
 		TEST_NLATTR_((fd_), (nlh0_), (hdrlen_),			\
 			(init_msg_), (print_msg_),			\

-- 
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/20170703/3d47cd3a/attachment.bin>


More information about the Strace-devel mailing list