From: Dmitry V. Levin Date: Fri, 7 Jul 2023 08:00:00 +0000 (+0000) Subject: test: fix use of ERRNO_IS_PRIVILEGE() X-Git-Tag: v254-rc3~37^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F28384%2Fhead;p=thirdparty%2Fsystemd.git test: fix use of ERRNO_IS_PRIVILEGE() 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. --- diff --git a/src/test/test-capability.c b/src/test/test-capability.c index bfdba4f2942..a45e06db22e 100644 --- a/src/test/test-capability.c +++ b/src/test/test-capability.c @@ -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); diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c index 07f43551425..51c8d8ee88c 100644 --- a/src/test/test-fileio.c +++ b/src/test/test-fileio.c @@ -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"));