Skip to content

Commit 3c7f7cb

Browse files
ldv-altbluca
authored andcommitted
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. (cherry picked from commit fce846e) (cherry picked from commit f1c4da0)
1 parent a6eca17 commit 3c7f7cb

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/test/test-capability.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static void test_last_cap_file(void) {
3838
int r;
3939

4040
r = read_one_line_file("/proc/sys/kernel/cap_last_cap", &content);
41-
if (r == -ENOENT || ERRNO_IS_PRIVILEGE(r)) /* kernel pre 3.2 or no access */
41+
if (r == -ENOENT || (r < 0 && ERRNO_IS_PRIVILEGE(r))) /* kernel pre 3.2 or no access */
4242
return;
4343
assert_se(r >= 0);
4444

@@ -234,7 +234,7 @@ static void test_ensure_cap_64bit(void) {
234234
int r;
235235

236236
r = read_one_line_file("/proc/sys/kernel/cap_last_cap", &content);
237-
if (r == -ENOENT || ERRNO_IS_PRIVILEGE(r)) /* kernel pre 3.2 or no access */
237+
if (r == -ENOENT || (r < 0 && ERRNO_IS_PRIVILEGE(r))) /* kernel pre 3.2 or no access */
238238
return;
239239
assert_se(r >= 0);
240240

src/test/test-fileio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ TEST(write_string_file_verify) {
458458
int r;
459459

460460
r = read_one_line_file("/proc/version", &buf);
461-
if (ERRNO_IS_PRIVILEGE(r))
461+
if (r < 0 && ERRNO_IS_PRIVILEGE(r))
462462
return;
463463
assert_se(r >= 0);
464464
assert_se(buf2 = strjoin(buf, "\n"));

0 commit comments

Comments
 (0)