From eb3635dd1f3f5ff9e0bdf7ec4bf14c78cbc4a015 Mon Sep 17 00:00:00 2001 From: NRK Date: Sat, 28 Jan 2023 21:34:29 +0600 Subject: swclock: fix codeql warning and upgrade to futimens this was reported by codeql's scan as a TOCTOU bug. while that's true in theory, i don't believe it would've had any practical effect. a better justification for this change might be the fact that it upgrades from `utime` (which is depreciated by POSIX [0]) to `futimens`. [0]: https://www.man7.org/linux/man-pages/man3/utime.3p.html#FUTURE_DIRECTIONS --- src/swclock/swclock.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/swclock') diff --git a/src/swclock/swclock.c b/src/swclock/swclock.c index e526bd38..83b15c95 100644 --- a/src/swclock/swclock.c +++ b/src/swclock/swclock.c @@ -78,14 +78,12 @@ int main(int argc, char **argv) eerrorx("swclock: Reference file was not specified"); if (sflag) { - if (stat(file, &sb) == -1) { - opt = open(file, O_WRONLY | O_CREAT, 0644); - if (opt == -1) - eerrorx("swclock: open: %s", strerror(errno)); - close(opt); - } else - if (utime(file, NULL) == -1) - eerrorx("swclock: utime: %s", strerror(errno)); + int fd = open(file, O_WRONLY | O_CREAT, 0644); + if (fd == -1) + eerrorx("swclock: open: %s", strerror(errno)); + if (futimens(fd, NULL) == -1) + eerrorx("swclock: futimens: %s", strerror(errno)); + close(fd); return 0; } -- cgit v1.2.3