diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-10-16 07:35:32 +0200 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@gmail.com> | 2024-10-16 11:06:57 +0200 |
commit | 7693e8d9d08a681fa7832565ca8da938f119bc7f (patch) | |
tree | 4a8bd4c2917a0609bb00c814ae4dc0b0f5cc62f9 /src/test/test-json.c | |
parent | Merge pull request #34742 from yuwata/test-storage (diff) | |
download | systemd-7693e8d9d08a681fa7832565ca8da938f119bc7f.tar.xz systemd-7693e8d9d08a681fa7832565ca8da938f119bc7f.zip |
test: fix TOCTOU in test-json
Follow-up for 60ae3b86fb52d545b279e3927d2214462385e734.
Fixes CID#1563782.
Diffstat (limited to 'src/test/test-json.c')
-rw-r--r-- | src/test/test-json.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/test/test-json.c b/src/test/test-json.c index c4df19e08d..8dd5746495 100644 --- a/src/test/test-json.c +++ b/src/test/test-json.c @@ -1372,8 +1372,8 @@ TEST(fd_info) { v = sd_json_variant_unref(v); fd = safe_close(fd); - if (access("/sys/class/net/lo/uevent", F_OK) >= 0) { - ASSERT_OK_ERRNO(fd = open("/sys/class/net/lo/uevent", O_CLOEXEC | O_PATH)); + fd = open("/sys/class/net/lo/uevent", O_CLOEXEC | O_PATH); + if (fd >= 0) { ASSERT_OK(json_variant_new_fd_info(&v, fd)); ASSERT_OK(sd_json_variant_dump(v, SD_JSON_FORMAT_PRETTY_AUTO | SD_JSON_FORMAT_COLOR_AUTO, NULL, NULL)); v = sd_json_variant_unref(v); @@ -1381,8 +1381,8 @@ TEST(fd_info) { } /* block device */ - if (access("/dev/sda", F_OK) >= 0) { - ASSERT_OK_ERRNO(fd = open("/dev/sda", O_CLOEXEC | O_PATH)); + fd = open("/dev/sda", O_CLOEXEC | O_PATH); + if (fd >= 0) { ASSERT_OK(json_variant_new_fd_info(&v, fd)); ASSERT_OK(sd_json_variant_dump(v, SD_JSON_FORMAT_PRETTY_AUTO | SD_JSON_FORMAT_COLOR_AUTO, NULL, NULL)); v = sd_json_variant_unref(v); |