diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-02-20 11:43:13 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2023-02-20 16:27:26 +0100 |
commit | c52c4d6974e3bc6d8ffdd3b73207617e06cd5157 (patch) | |
tree | 487a3aee5767979b21ec8246daed0ffde951b8e5 /src/test | |
parent | cap-list: refuse parsing numeric capability 63 (diff) | |
download | systemd-c52c4d6974e3bc6d8ffdd3b73207617e06cd5157.tar.xz systemd-c52c4d6974e3bc6d8ffdd3b73207617e06cd5157.zip |
cap-list: add CAPABILITY_TO_STRING() macro using compound initialization to allocate fallback buffer
Let's add a helper that can return a numeric string in case we don't
recognize a name for a capability.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test-cap-list.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/test/test-cap-list.c b/src/test/test-cap-list.c index 517641a019..8df425bdd2 100644 --- a/src/test/test-cap-list.c +++ b/src/test/test-cap-list.c @@ -14,6 +14,13 @@ TEST(cap_list) { assert_se(!capability_to_name(-1)); assert_se(!capability_to_name(capability_list_length())); + assert_se(!capability_to_name(63)); + assert_se(!capability_to_name(64)); + + assert_se(!CAPABILITY_TO_STRING(-1)); + if (capability_list_length() <= 62) + assert_se(streq(CAPABILITY_TO_STRING(62), "0x3e")); + assert_se(!CAPABILITY_TO_STRING(64)); for (int i = 0; i < capability_list_length(); i++) { const char *n; @@ -21,6 +28,8 @@ TEST(cap_list) { assert_se(n = capability_to_name(i)); assert_se(capability_from_name(n) == i); printf("%s = %i\n", n, i); + + assert_se(streq(CAPABILITY_TO_STRING(i), n)); } assert_se(capability_from_name("asdfbsd") == -EINVAL); |