On Sat, Jul 15, 2017 at 08:02:24AM +0800, JingPiao Chen wrote: > On Sat, Jul 15, 2017 at 02:45:01AM +0300, Dmitry V. Levin wrote: > > On Sat, Jul 15, 2017 at 12:22:57AM +0800, JingPiao Chen wrote: > > > On Fri, Jul 14, 2017 at 01:16:37PM +0800, JingPiao Chen wrote: > > > [...] > > > > +static void > > > > +test_selnl_msg_setenforce(const int fd) > > > > +{ > > > > + void *const nlh0 = tail_alloc(NLMSG_HDRLEN); > > > > + static char pattern[4096]; > > > > + fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); > > > > + > > > > + static const struct selnl_msg_setenforce msg = { > > > > + .val = 0xfbdcdfab > > > > + }; > > > > + TEST_NETLINK_OBJECT(fd, nlh0, > > > > + SELNL_MSG_SETENFORCE, NLM_F_REQUEST, > > > > + pattern, msg, > > > > + PRINT_FIELD_D("{", msg, val); > > > > + printf("}")); > > > > +} > > > > + > > > > +static void > > > > +test_selnl_msg_policyload(const int fd) > > > > +{ > > > > + void *const nlh0 = tail_alloc(NLMSG_HDRLEN); > > > > + static char pattern[4096]; > > > > + fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); > > > > > > Move ... > > > > > > > + > > > > + static const struct selnl_msg_policyload msg = { > > > > + .seqno = 0xabdcfabc > > > > + }; > > > > + TEST_NETLINK_OBJECT(fd, nlh0, > > > > + SELNL_MSG_POLICYLOAD, NLM_F_REQUEST, > > > > + pattern, msg, > > > > + PRINT_FIELD_U("{", msg, seqno); > > > > + printf("}")); > > > > +} > > > > + > > > > int main(void) > > > > { > > > > skip_if_unavailable("/proc/self/fd/"); > > > > @@ -57,6 +103,9 @@ int main(void) > > > > int fd = create_nl_socket(NETLINK_SELINUX); > > > > > > > > test_nlmsg_type(fd); > > > > + test_selnl_msg_unspec(fd); > > > > + test_selnl_msg_setenforce(fd); > > > > + test_selnl_msg_policyload(fd); > > > > > > > > printf("+++ exited with 0 +++\n"); > > > > > > > > diff --git a/tests/test_netlink.h b/tests/test_netlink.h > > > > index 7049128..b6f6ac9 100644 > > > > --- a/tests/test_netlink.h > > > > +++ b/tests/test_netlink.h > > > > @@ -45,3 +45,33 @@ > > > > (type_), #type_, > > > > \ > > > > (flags_), #flags_, > > > > \ > > > > (data_len_), (src_), (slen_), __VA_ARGS__) > > > > + > > > > +#define TEST_NETLINK_OBJECT(fd_, nlh0_, > > > > \ > > > > + type_, flags_, > > > > \ > > > > + pattern_, obj_, ...) > > > > \ > > > > + do { > > > > \ > > > > + const unsigned int plen = > > > > \ > > > > + sizeof(obj_) - 1 > DEFAULT_STRLEN > > > > \ > > > > + ? DEFAULT_STRLEN : (int) sizeof(obj_) - 1; > > > > \ > > > > > > ... here. The template of TEST_NETLINK_OBJECT is TEST_NLATTR_OBJECT. > > > I think pattern can declare here instead of in the caller. > > > If this thought is ok, I will send version 2. > > > > Do you want to create a private pattern[4096] in every invocation > > of TEST_NETLINK_OBJECT macro? > > Yes, Is that ok? I hope you can give me some advice. Thank you.
If you want to create a local pattern[], no need to create it that big. Assuming that you never read more than plen bytes from the pattern, pattern[DEFAULT_STRLEN] should be enough. -- ldv
signature.asc
Description: PGP signature
------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel