]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: fix use of ERRNO_IS_PRIVILEGE() 28384/head
authorDmitry V. Levin <ldv@strace.io>
Fri, 7 Jul 2023 08:00:00 +0000 (08:00 +0000)
committerDmitry V. Levin <ldv@strace.io>
Sun, 16 Jul 2023 10:53:30 +0000 (10:53 +0000)
Given that ERRNO_IS_PRIVILEGE() also matches positive values,
make sure this macro is not called with arguments that do not have
errno semantics.

In this case the arguments passed to ERRNO_IS_PRIVILEGE() are the values
returned by read_one_line_file() which can legitimately return positive
values without errno semantics, so fix this by moving ERRNO_IS_PRIVILEGE()
invocations to the branches where the return values are known to be negative.

src/test/test-capability.c
src/test/test-fileio.c

index bfdba4f29424d691c6d7cccf64a6bbde020056a5..a45e06db22e7115d1f8a15de6fa7929cf9882df0 100644 (file)
@@ -39,7 +39,7 @@ static void test_last_cap_file(void) {
         int r;
 
         r = read_one_line_file("/proc/sys/kernel/cap_last_cap", &content);
-        if (r == -ENOENT || ERRNO_IS_PRIVILEGE(r)) /* kernel pre 3.2 or no access */
+        if (r == -ENOENT || (r < 0 && ERRNO_IS_PRIVILEGE(r))) /* kernel pre 3.2 or no access */
                 return;
         assert_se(r >= 0);
 
@@ -235,7 +235,7 @@ static void test_ensure_cap_64_bit(void) {
         int r;
 
         r = read_one_line_file("/proc/sys/kernel/cap_last_cap", &content);
-        if (r == -ENOENT || ERRNO_IS_PRIVILEGE(r)) /* kernel pre 3.2 or no access */
+        if (r == -ENOENT || (r < 0 && ERRNO_IS_PRIVILEGE(r))) /* kernel pre 3.2 or no access */
                 return;
         assert_se(r >= 0);
 
index 07f4355142575de9db1bc2d9cb6d03a91b6073b6..51c8d8ee88c812b66320ff4742b4124304f58c6a 100644 (file)
@@ -490,7 +490,7 @@ TEST(write_string_file_verify) {
         int r;
 
         r = read_one_line_file("/proc/version", &buf);
-        if (ERRNO_IS_PRIVILEGE(r))
+        if (r < 0 && ERRNO_IS_PRIVILEGE(r))
                 return;
         assert_se(r >= 0);
         assert_se(buf2 = strjoin(buf, "\n"));