[PATCH v4 05/11] tests: fix TEST_NLATTR_OBJECT and TEST_NLATTR_ARRAY use for large objects

JingPiao Chen chenjingpiao at gmail.com
Thu Jul 6 14:58:59 UTC 2017


On Thu, Jul 06, 2017 at 02:48:51PM +0300, Dmitry V. Levin wrote:
> On Thu, Jul 06, 2017 at 09:57:31AM +0800, JingPiao Chen wrote:
> > commit v4.17-161-gdbd0605 adjust TEST_NLATTR_OBJECT and
> > TEST_NLATTR_ARRAY for large objects, only change the pattern
> > print length, still pass a big length for nla_data_len, do not
> > change strace output, still output '"STR"...'.
> > 
> > * tests/test_nlattr.h (TEST_NLATTR_OBJECT, TEST_NLATTR_ARRAY):
> > In case of len < sizeof(object), pass plen as nla_data_len and slen.
> > ---
> >  tests/test_nlattr.h | 6 ++----
> >  1 file changed, 2 insertions(+), 4 deletions(-)
> > 
> > diff --git a/tests/test_nlattr.h b/tests/test_nlattr.h
> > index 9c15c33..4a2af02 100644
> > --- a/tests/test_nlattr.h
> > +++ b/tests/test_nlattr.h
> > @@ -108,8 +108,7 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type)
> >  		TEST_NLATTR_((fd_), (nlh0_), (hdrlen_),			\
> >  			(init_msg_), (print_msg_),			\
> >  			(nla_type_), #nla_type_,			\
> > -			sizeof(obj_) - 1,				\
> > -			(pattern_), sizeof(obj_) - 1,			\
> > +			plen, (pattern_), plen,				\
> >  			print_quoted_hex((pattern_), plen));		\
> >  		/* short read of sizeof(obj_) */			\
> >  		TEST_NLATTR_((fd_), (nlh0_), (hdrlen_),			\
> > @@ -139,8 +138,7 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type)
> >  		TEST_NLATTR_((fd_), (nlh0_), (hdrlen_),			\
> >  			(init_msg_), (print_msg_),			\
> >  			(nla_type_), #nla_type_,			\
> > -			sizeof((obj_)[0]) - 1,				\
> > -			(pattern_), sizeof((obj_)[0]) - 1,		\
> > +			plen, (pattern_), plen,				\
> >  			print_quoted_hex((pattern_), plen));		\
> >  		/* sizeof((obj_)[0]) < len < sizeof(obj_) */		\
> >  		TEST_NLATTR_((fd_), (nlh0_), (hdrlen_),			\
> 
> I don't see why this change is needed.  I thought it's fine to pass an
> object larger than plen as long as it's smaller than expected by strace.

I think you can apply [PATCH v4 03/11],  [PATCH v4 04/11]
and [PATCH v4 06/11] to see what happen, test log above:

-{{nla_len=47, nla_type=PACKET_DIAG_MCLIST}, "abcdefghijklmnopqrstuvwxyzabcdef"}}
+{{nla_len=47, nla_type=PACKET_DIAG_MCLIST}, "abcdefghijklmnopqrstuvwxyzabcdef"...}}

--- exp	2017-07-06 22:54:20.617639241 +0800
+++ log	2017-07-06 22:54:20.617639241 +0800
@@ -1,5 +1,5 @@
-sendto(3, {{len=79, type=SOCK_DIAG_BY_FAMILY, flags=NLM_F_DUMP, seq=0, pid=0}, {pdiag_family=AF_PACKET, pdiag_type=SOCK_STREAM, pdiag_num=0, pdiag_ino=0, pdiag_cookie=[0, 0]}, {{nla_len=47, nla_type=PACKET_DIAG_MCLIST}, "abcdefghijklmnopqrstuvwxyzabcdef"}}, 79, MSG_DONTWAIT, NULL, 0) = 79
-sendto(3, {{len=123, type=SOCK_DIAG_BY_FAMILY, flags=NLM_F_DUMP, seq=0, pid=0}, {pdiag_family=AF_PACKET, pdiag_type=SOCK_STREAM, pdiag_num=0, pdiag_ino=0, pdiag_cookie=[0, 0]}, {{nla_len=91, nla_type=PACKET_DIAG_MCLIST}, [{pdmc_index=if_nametoindex("lo"), pdmc_count=2882383612, pdmc_type=52655, pdmc_alen=4, pdmc_addr=1234}]}}, 123, MSG_DONTWAIT, NULL, 0) = 123
-sendto(3, {{len=124, type=SOCK_DIAG_BY_FAMILY, flags=NLM_F_DUMP, seq=0, pid=0}, {pdiag_family=AF_PACKET, pdiag_type=SOCK_STREAM, pdiag_num=0, pdiag_ino=0, pdiag_cookie=[0, 0]}, {{nla_len=92, nla_type=PACKET_DIAG_MCLIST}, [{pdmc_index=if_nametoindex("lo"), pdmc_count=2882383612, pdmc_type=52655, pdmc_alen=4, pdmc_addr=1234}, 0x7f09e2a90fd5]}}, 124, MSG_DONTWAIT, NULL, 0) = -1 EFAULT (Bad address)
-sendto(3, {{len=124, type=SOCK_DIAG_BY_FAMILY, flags=NLM_F_DUMP, seq=0, pid=0}, {pdiag_family=AF_PACKET, pdiag_type=SOCK_STREAM, pdiag_num=0, pdiag_ino=0, pdiag_cookie=[0, 0]}, {{nla_len=92, nla_type=PACKET_DIAG_MCLIST}, [{pdmc_index=if_nametoindex("lo"), pdmc_count=2882383612, pdmc_type=52655, pdmc_alen=4, pdmc_addr=1234}, {pdmc_index=if_nametoindex("lo"), pdmc_count=3673156348, pdmc_type=44527, pdmc_alen=4, pdmc_addr=5678}]}}, 124, MSG_DONTWAIT, NULL, 0) = 124
+sendto(3, {{len=79, type=SOCK_DIAG_BY_FAMILY, flags=NLM_F_DUMP, seq=0, pid=0}, {pdiag_family=AF_PACKET, pdiag_type=SOCK_STREAM, pdiag_num=0, pdiag_ino=0, pdiag_cookie=[0, 0]}, {{nla_len=47, nla_type=PACKET_DIAG_MCLIST}, "abcdefghijklmnopqrstuvwxyzabcdef"...}}, 79, MSG_DONTWAIT, NULL, 0) = 79
+sendto(3, {{len=123, type=SOCK_DIAG_BY_FAMILY, flags=NLM_F_DUMP, seq=0, pid=0}, {pdiag_family=AF_PACKET, pdiag_type=SOCK_STREAM, pdiag_num=0, pdiag_ino=0, pdiag_cookie=[0, 0]}, {{nla_len=91, nla_type=PACKET_DIAG_MCLIST}, [{pdmc_index=if_nametoindex("lo"), pdmc_count=2882383612, pdmc_type=52655, pdmc_alen=4, pdmc_addr="1234"}]}}, 123, MSG_DONTWAIT, NULL, 0) = 123
+sendto(3, {{len=124, type=SOCK_DIAG_BY_FAMILY, flags=NLM_F_DUMP, seq=0, pid=0}, {pdiag_family=AF_PACKET, pdiag_type=SOCK_STREAM, pdiag_num=0, pdiag_ino=0, pdiag_cookie=[0, 0]}, {{nla_len=92, nla_type=PACKET_DIAG_MCLIST}, [{pdmc_index=if_nametoindex("lo"), pdmc_count=2882383612, pdmc_type=52655, pdmc_alen=4, pdmc_addr="1234"}, 0x7f09e2a90fd5]}}, 124, MSG_DONTWAIT, NULL, 0) = -1 EFAULT (Bad address)
+sendto(3, {{len=124, type=SOCK_DIAG_BY_FAMILY, flags=NLM_F_DUMP, seq=0, pid=0}, {pdiag_family=AF_PACKET, pdiag_type=SOCK_STREAM, pdiag_num=0, pdiag_ino=0, pdiag_cookie=[0, 0]}, {{nla_len=92, nla_type=PACKET_DIAG_MCLIST}, [{pdmc_index=if_nametoindex("lo"), pdmc_count=2882383612, pdmc_type=52655, pdmc_alen=4, pdmc_addr="1234"}, {pdmc_index=if_nametoindex("lo"), pdmc_count=3673156348, pdmc_type=44527, pdmc_alen=4, pdmc_addr="5678"}]}}, 124, MSG_DONTWAIT, NULL, 0) = 124
 +++ exited with 0 +++

 --
 JingPiao Chen




More information about the Strace-devel mailing list