Skip to content

Commit f1c4da0

Browse files
ldv-altkeszybz
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)
1 parent 791dbff commit f1c4da0

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
@@ -457,7 +457,7 @@ TEST(write_string_file_verify) {
457457
int r;
458458

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

0 commit comments

Comments
 (0)