[PATCH 08/26] tests: Additional capset decoder checks

Eugene Syromyatnikov evgsyr at gmail.com
Mon Oct 24 03:00:52 UTC 2016


* caps.awk: Add patterns for additional checks.
* caps.c: Implement additional checks.
---
 tests/caps.awk |   16 +++++++++++++---
 tests/caps.c   |   28 +++++++++++++++++++++++++++-
 2 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/tests/caps.awk b/tests/caps.awk
index 67003ac..6130482 100644
--- a/tests/caps.awk
+++ b/tests/caps.awk
@@ -31,16 +31,26 @@ BEGIN {
 	cap = "(0|1<<CAP_[A-Z_]+(\\|1<<CAP_[A-Z_]+)*|1<<CAP_[A-Z_]+(\\|1<<CAP_[A-Z_]+){37}\\|0xffffffc0)"
 	s_efault = "-1 EFAULT (Bad address)"
 	r_efault = "-1 EFAULT \\(Bad address\\)"
+	r_einval = "-1 EINVAL \\(Invalid argument\\)"
 	r_addr = "0x[[:xdigit:]]+"
 	s[1] = "capget(NULL, NULL) = " s_efault
 	r[2] = "^capget\\(" r_addr ", " r_addr "\\) = " r_efault
 	r[3] = "^capget\\(\\{_LINUX_CAPABILITY_VERSION_3, 0\\}, " r_addr "\\) = " r_efault
 	r[4] = "^capget\\(\\{_LINUX_CAPABILITY_VERSION_3, 0\\}, \\{" cap ", " cap ", " cap "\\}\\) = 0$"
+
+	capset_v1_data = "{1<<CAP_DAC_OVERRIDE, 1<<CAP_DAC_READ_SEARCH, 0}"
+	capset_v3hi_data = "{1<<CAP_WAKE_ALARM, 1<<CAP_BLOCK_SUSPEND, 0}"
 	capset_data = "{1<<CAP_DAC_OVERRIDE|1<<CAP_WAKE_ALARM, 1<<CAP_DAC_READ_SEARCH|1<<CAP_BLOCK_SUSPEND, 0}"
-	s[5] = "capset({_LINUX_CAPABILITY_VERSION_3, 0}, " capset_data ") = -1 EPERM (Operation not permitted)"
-	s[6] = "+++ exited with 0 +++"
+	s[5] = "capset(NULL, NULL) = " s_efault
+	r[6] = "^capset\\(" r_addr ", " r_addr "\\) = " r_efault
+	r[7] = "^capset\\(\\{0xbadc0ded /\\* _LINUX_CAPABILITY_VERSION_\\?\\?\\? \\*/, -1576685468\\}, " r_addr "\\) = " r_einval
+	r[8] = "^capset\\(\\{_LINUX_CAPABILITY_VERSION_2, 0\\}, " r_addr "\\) = " r_efault
+	s[9] = "capset({_LINUX_CAPABILITY_VERSION_3, 0}, " capset_data ") = -1 EPERM (Operation not permitted)"
+	s[10] = "capset({_LINUX_CAPABILITY_VERSION_3, 0}, " capset_v3hi_data ") = -1 EPERM (Operation not permitted)"
+	s[11] = "capset({_LINUX_CAPABILITY_VERSION_1, 0}, " capset_v1_data ") = -1 EPERM (Operation not permitted)"
+	s[12] = "+++ exited with 0 +++"
 
-	lines = 6
+	lines = 12
 	fail = 0
 }
 
diff --git a/tests/caps.c b/tests/caps.c
index 17e1077..9f33a39 100644
--- a/tests/caps.c
+++ b/tests/caps.c
@@ -38,6 +38,8 @@ int
 main(void)
 {
 	const int data[] = { 2, 4, 0, 8, 16, 0 };
+	const int v1 = 0x19980330;
+	const int v2 = 0x20071026;
 	const int v3 = 0x20080522;
 
 	int * const head = tail_alloc(sizeof(int) * 2);
@@ -55,7 +57,31 @@ main(void)
 		error_msg_and_skip("capget: v3 expected");
 
 	memcpy(tail_data, data, sizeof(data));
-	if (capset(head, data) == 0 || errno != EPERM)
+
+	capset(NULL, NULL);
+	capset(head + 2, tail_data);
+
+	head[0] = 0xbadc0ded;
+	head[1] = 2718281828U;
+	capset(head, tail_data + ARRAY_SIZE(data) - 2);
+
+	head[0] = v2;
+	head[1] = 0;
+	capset(head, tail_data + ARRAY_SIZE(data) - 5);
+
+	memcpy(tail_data, data, sizeof(data));
+	head[0] = v3;
+	if (capset(head, tail_data) == 0 || errno != EPERM)
+		perror_msg_and_skip("capset");
+
+	memset(tail_data, 0, sizeof(data) / 2);
+	if (capset(head, tail_data) == 0 || errno != EPERM)
+		perror_msg_and_skip("capset");
+
+	memcpy(tail_data + ARRAY_SIZE(data) / 2, data, sizeof(data) / 2);
+	head[0] = v1;
+	if (capset(head, tail_data + ARRAY_SIZE(data) / 2) == 0 ||
+	    errno != EPERM)
 		perror_msg_and_skip("capset");
 
 	return 0;
-- 
1.7.10.4





More information about the Strace-devel mailing list