aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNRK <nrk@disroot.org>2023-01-28 21:34:29 +0600
committerMike Frysinger <vapier@gmail.com>2023-01-28 16:19:33 -0500
commiteb3635dd1f3f5ff9e0bdf7ec4bf14c78cbc4a015 (patch)
tree4619b681b612bdaafa202aedfaef1fdd06e55954 /src
parent459783bbad912e5eda6533959c09b94db1d385d1 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/swclock/swclock.c14
1 files changed, 6 insertions, 8 deletions
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;
}