]> git.armaanb.net Git - opendoas.git/commitdiff
timestamp.c: check fstat(2) instead of separate stat(2)
authorDuncan Overbruck <mail@duncano.de>
Mon, 3 Feb 2020 21:19:45 +0000 (22:19 +0100)
committerDuncan Overbruck <mail@duncano.de>
Mon, 3 Feb 2020 21:41:30 +0000 (22:41 +0100)
timestamp.c

index 75a3af7cbf6572bfa7086d83bf33654b69f5948f..c7edb56409e109aea271e04b9ad51f5e5e21cfac 100644 (file)
@@ -202,6 +202,8 @@ timestamp_check(int fd, int secs)
 
        if (fstat(fd, &st) == -1)
                err(1, "fstat");
 
        if (fstat(fd, &st) == -1)
                err(1, "fstat");
+       if (st.st_uid != 0 || st.st_gid != getgid() || st.st_mode != (S_IFREG | 0000))
+               errx(1, "timestamp uid, gid or mode wrong");
 
        if (!timespecisset(&st.st_atim) || !timespecisset(&st.st_mtim)) {
                warnx("timestamp atim or mtime not set");
 
        if (!timespecisset(&st.st_atim) || !timespecisset(&st.st_mtim)) {
                warnx("timestamp atim or mtime not set");
@@ -254,9 +256,6 @@ timestamp_open(int *valid, int secs)
        if (timestamp_path(path, sizeof path) == -1)
                return -1;
 
        if (timestamp_path(path, sizeof path) == -1)
                return -1;
 
-       if (stat(path, &st) != -1 && (st.st_uid != 0 || st.st_gid != getgid()|| st.st_mode != (S_IFREG | 0000)))
-               return -1;
-
        fd = open(path, O_RDONLY|O_NOFOLLOW);
        if (fd == -1) {
                char tmp[256];
        fd = open(path, O_RDONLY|O_NOFOLLOW);
        if (fd == -1) {
                char tmp[256];