From c9e520582586dd309462646d330654e02c531226 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Thu, 10 Oct 2019 18:19:31 +0200
Subject: [PATCH 59/76] 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.
---
tests/nlattr_crypto_user_alg.c | 14 +++++++++-----
tests/test_nlattr.h | 27 +++++++++++++++++----------
2 files changed, 26 insertions(+), 15 deletions(-)
Index: strace-5.1/tests/nlattr_crypto_user_alg.c
===================================================================
--- strace-5.1.orig/tests/nlattr_crypto_user_alg.c 2018-12-30 16:35:21.000000000 +0100
+++ strace-5.1/tests/nlattr_crypto_user_alg.c 2020-01-29 12:33:55.598689093 +0100
@@ -85,7 +85,8 @@
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 @@
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 @@
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 @@
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 @@
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: strace-5.1/tests/test_nlattr.h
===================================================================
--- strace-5.1.orig/tests/test_nlattr.h 2018-12-10 01:00:00.000000000 +0100
+++ strace-5.1/tests/test_nlattr.h 2020-01-29 12:33:55.604689038 +0100
@@ -96,11 +96,9 @@
#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 @@
(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 @@
#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 @@
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_, \
Index: strace-5.1/tests-m32/nlattr_crypto_user_alg.c
===================================================================
--- strace-5.1.orig/tests-m32/nlattr_crypto_user_alg.c 2018-12-30 16:35:21.000000000 +0100
+++ strace-5.1/tests-m32/nlattr_crypto_user_alg.c 2020-01-29 12:35:29.940886920 +0100
@@ -85,7 +85,8 @@
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 @@
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 @@
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 @@
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 @@
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: strace-5.1/tests-m32/test_nlattr.h
===================================================================
--- strace-5.1.orig/tests-m32/test_nlattr.h 2018-12-10 01:00:00.000000000 +0100
+++ strace-5.1/tests-m32/test_nlattr.h 2020-01-29 12:35:30.010886327 +0100
@@ -96,11 +96,9 @@
#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 @@
(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 @@
#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 @@
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_, \
Index: strace-5.1/tests-mx32/nlattr_crypto_user_alg.c
===================================================================
--- strace-5.1.orig/tests-mx32/nlattr_crypto_user_alg.c 2018-12-30 16:35:21.000000000 +0100
+++ strace-5.1/tests-mx32/nlattr_crypto_user_alg.c 2020-01-29 12:35:29.946886869 +0100
@@ -85,7 +85,8 @@
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 @@
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 @@
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 @@
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 @@
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: strace-5.1/tests-mx32/test_nlattr.h
===================================================================
--- strace-5.1.orig/tests-mx32/test_nlattr.h 2018-12-10 01:00:00.000000000 +0100
+++ strace-5.1/tests-mx32/test_nlattr.h 2020-01-29 12:35:30.012886310 +0100
@@ -96,11 +96,9 @@
#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 @@
(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 @@
#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 @@
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_, \