From: Eugene Syromyatnikov Date: Thu, 10 Oct 2019 16:19:31 +0000 (+0200) Subject: tests: introduce TEST_NLATTR_OBJECT_MINSZ X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1e50b09fa717fc179fea6714ceb4e5f2572cc187;p=strace tests: introduce TEST_NLATTR_OBJECT_MINSZ 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. --- diff --git a/tests/nlattr_crypto_user_alg.c b/tests/nlattr_crypto_user_alg.c index f90c6208..e0ecdd3d 100644 --- a/tests/nlattr_crypto_user_alg.c +++ b/tests/nlattr_crypto_user_alg.c @@ -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); diff --git a/tests/test_nlattr.h b/tests/test_nlattr.h index 8b8c66b8..4df25c29 100644 --- a/tests/test_nlattr.h +++ b/tests/test_nlattr.h @@ -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_, \