]> granicus.if.org Git - strace/commitdiff
tests: introduce TEST_NLATTR_OBJECT_MINSZ
authorEugene Syromyatnikov <evgsyr@gmail.com>
Thu, 10 Oct 2019 16:19:31 +0000 (18:19 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 18 Oct 2019 20:00:48 +0000 (20:00 +0000)
It is useful in cases where a structure grows over time and we support
decoding of only part of it.

* tests/test_nlattr.h (TEST_NLATTR_OBJECT_EX_, TEST_NLATTR_OBJECT_EX):
Add minsz_ parameter, use it instead of sizeof(obj_).
(TEST_NLATTR_OBJECT): Pass sizeof(obj_) as minsz_.
(TEST_NLATTR_OBJECT_MINSZ): New macro.
* tests/nlattr_crypto_user_alg.c (main): Add proper minsz_ argument to
TEST_NLATTR_OBJECT_EX instances.

tests/nlattr_crypto_user_alg.c
tests/test_nlattr.h

index f90c620826621e97830dc043df591709b8039130..e0ecdd3d5300e7833bfa5b73b405a1f6e1de9d3c 100644 (file)
@@ -85,7 +85,8 @@ main(void)
        TEST_NLATTR_OBJECT_EX(fd, nlh0, hdrlen,
                              init_crypto_user_alg, print_crypto_user_alg,
                              CRYPTOCFGA_REPORT_HASH,
-                             pattern, rhash, print_quoted_memory,
+                             pattern, rhash, sizeof(rhash),
+                             print_quoted_memory,
                              printf("{type=\"efgh\"");
                              PRINT_FIELD_U(", ", rhash, blocksize);
                              PRINT_FIELD_U(", ", rhash, digestsize);
@@ -104,7 +105,8 @@ main(void)
        TEST_NLATTR_OBJECT_EX(fd, nlh0, hdrlen,
                              init_crypto_user_alg, print_crypto_user_alg,
                              CRYPTOCFGA_REPORT_BLKCIPHER,
-                             pattern, rblkcipher, print_quoted_memory,
+                             pattern, rblkcipher, sizeof(rblkcipher),
+                             print_quoted_memory,
                              printf("{type=\"abcd\", geniv=\"efgh\"");
                              PRINT_FIELD_U(", ", rblkcipher, blocksize);
                              PRINT_FIELD_U(", ", rblkcipher, min_keysize);
@@ -124,7 +126,8 @@ main(void)
        TEST_NLATTR_OBJECT_EX(fd, nlh0, hdrlen,
                              init_crypto_user_alg, print_crypto_user_alg,
                              CRYPTOCFGA_REPORT_AEAD,
-                             pattern, raead, print_quoted_memory,
+                             pattern, raead, sizeof(raead),
+                             print_quoted_memory,
                              printf("{type=\"abcd\", geniv=\"efgh\"");
                              PRINT_FIELD_U(", ", raead, blocksize);
                              PRINT_FIELD_U(", ", raead, maxauthsize);
@@ -140,7 +143,7 @@ main(void)
        TEST_NLATTR_OBJECT_EX(fd, nlh0, hdrlen,
                              init_crypto_user_alg, print_crypto_user_alg,
                              CRYPTOCFGA_REPORT_RNG,
-                             pattern, rrng, print_quoted_memory,
+                             pattern, rrng, sizeof(rrng), print_quoted_memory,
                              printf("{type=\"abcd\"");
                              PRINT_FIELD_U(", ", rrng, seedsize);
                              printf("}"));
@@ -156,7 +159,8 @@ main(void)
        TEST_NLATTR_OBJECT_EX(fd, nlh0, hdrlen,
                              init_crypto_user_alg, print_crypto_user_alg,
                              CRYPTOCFGA_REPORT_CIPHER,
-                             pattern, rcipher, print_quoted_memory,
+                             pattern, rcipher, sizeof(rcipher),
+                             print_quoted_memory,
                              printf("{type=\"abcd\"");
                              PRINT_FIELD_U(", ", rcipher, blocksize);
                              PRINT_FIELD_U(", ", rcipher, min_keysize);
index 8b8c66b8d645abfb406bb1f05482c2c4e3b7d168..4df25c29acefe33a7834489b8244db68b7cb0c74 100644 (file)
@@ -96,11 +96,9 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type, bool add_da
 #define TEST_NLATTR_OBJECT_EX_(fd_, nlh0_, hdrlen_,                    \
                               init_msg_, print_msg_,                   \
                               nla_type_, nla_type_str_,                \
-                              pattern_, obj_, fallback_func, ...)      \
+                              pattern_, obj_, minsz_, fallback_func, ...) \
        do {                                                            \
-               const unsigned int plen =                               \
-                       sizeof(obj_) - 1 > DEFAULT_STRLEN               \
-                       ? DEFAULT_STRLEN : (int) sizeof(obj_) - 1;      \
+               const unsigned int plen = MIN((minsz_) - 1, DEFAULT_STRLEN); \
                /* len < sizeof(obj_) */                                \
                if (plen > 0)                                           \
                        TEST_NLATTR_((fd_), (nlh0_), (hdrlen_),         \
@@ -113,7 +111,7 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type, bool add_da
                        (init_msg_), (print_msg_),                      \
                        (nla_type_), (nla_type_str_),                   \
                        sizeof(obj_),                                   \
-                       (pattern_), sizeof(obj_) - 1,                   \
+                       (pattern_), (minsz_) - 1,                       \
                        printf("%p",                                    \
                               RTA_DATA(NLMSG_ATTR(nlh, (hdrlen_)))));  \
                /* sizeof(obj_) */                                      \
@@ -128,12 +126,12 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type, bool add_da
 #define TEST_NLATTR_OBJECT_EX(fd_, nlh0_, hdrlen_,                     \
                              init_msg_, print_msg_,                    \
                              nla_type_,                                \
-                             pattern_, obj_, fallback_func, ...)       \
+                             pattern_, obj_, minsz_, fallback_func, ...) \
        TEST_NLATTR_OBJECT_EX_((fd_), (nlh0_), (hdrlen_),               \
                               (init_msg_), (print_msg_),               \
                               (nla_type_), #nla_type_,                 \
-                              (pattern_), (obj_), (fallback_func),     \
-                              __VA_ARGS__)
+                              (pattern_), (obj_), (minsz_),            \
+                              (fallback_func), __VA_ARGS__)
 
 #define TEST_NLATTR_OBJECT(fd_, nlh0_, hdrlen_,                                \
                           init_msg_, print_msg_,                       \
@@ -141,8 +139,17 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type, bool add_da
        TEST_NLATTR_OBJECT_EX_((fd_), (nlh0_), (hdrlen_),               \
                               (init_msg_), (print_msg_),               \
                               (nla_type_), #nla_type_,                 \
-                              (pattern_), (obj_), print_quoted_hex,    \
-                              __VA_ARGS__)
+                              (pattern_), (obj_), sizeof(obj_),        \
+                              print_quoted_hex, __VA_ARGS__)
+
+#define TEST_NLATTR_OBJECT_MINSZ(fd_, nlh0_, hdrlen_,                  \
+                          init_msg_, print_msg_,                       \
+                          nla_type_, pattern_, obj_, minsz_, ...)      \
+       TEST_NLATTR_OBJECT_EX_((fd_), (nlh0_), (hdrlen_),               \
+                              (init_msg_), (print_msg_),               \
+                              (nla_type_), #nla_type_,                 \
+                              (pattern_), (obj_), (minsz_),            \
+                              print_quoted_hex, __VA_ARGS__)
 
 #define TEST_NLATTR_ARRAY(fd_, nlh0_, hdrlen_,                         \
                          init_msg_, print_msg_,                        \