]> granicus.if.org Git - strace/commitdiff
tests: adjust TEST_NLATTR_OBJECT and TEST_NLATTR_ARRAY for large objects
authorDmitry V. Levin <ldv@altlinux.org>
Mon, 3 Jul 2017 15:14:54 +0000 (15:14 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 3 Jul 2017 15:14:54 +0000 (15:14 +0000)
* tests/test_nlattr.h (TEST_NLATTR_OBJECT, TEST_NLATTR_ARRAY): Add
support for objects larger than DEFAULT_STRLEN.
* tests/nlattr_inet_diag_msg.c (main): Change pattern size
from DEFAULT_STRLEN to 4096.
* tests/nlattr_netlink_diag_msg.c: Likewise.
* tests/nlattr_unix_diag_msg.c: Likewise.

Reported-by: JingPiao Chen <chenjingpiao@gmail.com>
tests/nlattr_inet_diag_msg.c
tests/nlattr_netlink_diag_msg.c
tests/nlattr_unix_diag_msg.c
tests/test_nlattr.h

index 306b86654ae8fe4efb176b267af78e527aee9ed3..d9d564c32fddda5ca6db01e0ebf702f132781484 100644 (file)
@@ -96,7 +96,7 @@ main(void)
        const unsigned int hdrlen = sizeof(struct inet_diag_msg);
        void *const nlh0 = tail_alloc(NLMSG_SPACE(hdrlen));
 
-       static char pattern[DEFAULT_STRLEN];
+       static char pattern[4096];
        fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
 
        static const struct inet_diag_meminfo minfo = {
index 37e3a012783767b5016621336662b87aeac54136..76a2d19e47dfea56d9741ab04942065228566080 100644 (file)
@@ -80,7 +80,7 @@ main(void)
        const unsigned int hdrlen = sizeof(struct netlink_diag_msg);
        void *const nlh0 = tail_alloc(NLMSG_SPACE(hdrlen));
 
-       static char pattern[DEFAULT_STRLEN];
+       static char pattern[4096];
        fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
 
        static const unsigned long groups[] = {
index a11328b19dc9410236792ccb3532b5d34a6b2b5f..229540428a8592e1e35184c1f3932ef4b8a2a048 100644 (file)
@@ -79,7 +79,7 @@ main(void)
        const unsigned int hdrlen = sizeof(struct unix_diag_msg);
        void *const nlh0 = tail_alloc(NLMSG_SPACE(hdrlen));
 
-       static char pattern[DEFAULT_STRLEN];
+       static char pattern[4096];
        fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
 
        static const struct unix_diag_vfs uv = {
index 097e637f1ca2702d099514deed1c141a77b9fda0..8cbb2115c28f13574fc2cd0af289007d2a3c4d52 100644 (file)
@@ -99,14 +99,15 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type)
                           init_msg_, print_msg_,                       \
                           nla_type_, pattern_, obj_, ...)              \
        do {                                                            \
+               const int plen = sizeof(obj_) - 1 > DEFAULT_STRLEN      \
+                       ? DEFAULT_STRLEN : (int) 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_)));           \
+                       printf("\"%.*s\"", plen, (pattern_)));          \
                /* short read of sizeof(obj_) */                        \
                TEST_NLATTR_((fd_), (nlh0_), (hdrlen_),                 \
                        (init_msg_), (print_msg_),                      \
@@ -128,15 +129,16 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type)
                          init_msg_, print_msg_,                        \
                          nla_type_, pattern_, obj_, print_elem_)       \
        do {                                                            \
+               const int plen =                                        \
+                       sizeof((obj_)[0]) - 1 > DEFAULT_STRLEN          \
+                       ? DEFAULT_STRLEN : (int) 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_)));                            \
+                       printf("\"%.*s\"", plen, (pattern_)));          \
                /* sizeof((obj_)[0]) < len < sizeof(obj_) */            \
                TEST_NLATTR_((fd_), (nlh0_), (hdrlen_),                 \
                        (init_msg_), (print_msg_),                      \