From fce846e0ace95920155088a7e70dac914e437e68 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Fri, 7 Jul 2023 08:00:00 +0000 Subject: [PATCH] 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. --- src/test/test-capability.c | 4 ++-- src/test/test-fileio.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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")); -- 2.47.3