]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Really fix the TOCTOU error.
authorRoy Marples <roy@marples.name>
Tue, 3 May 2016 12:19:35 +0000 (12:19 +0000)
committerRoy Marples <roy@marples.name>
Tue, 3 May 2016 12:19:35 +0000 (12:19 +0000)
dhcp6.c

diff --git a/dhcp6.c b/dhcp6.c
index 391d5c6b3ef536011cbb770f54b7659b591dd4df..2fc0257bda0455cc4cce772a8f9753622b8ee993 100644 (file)
--- a/dhcp6.c
+++ b/dhcp6.c
@@ -2176,10 +2176,11 @@ dhcp6_readlease(struct interface *ifp, int validate)
        } else {
                logger(ifp->ctx, LOG_DEBUG, "%s: reading lease `%s'",
                    ifp->name, state->leasefile);
-               if (stat(state->leasefile, &st) == -1)
+               fd = open(state->leasefile, O_RDONLY);
+               if (fd != -1 && fstat(fd, &st) == -1) {
+                       close(fd);
                        fd = -1;
-               else
-                       fd = open(state->leasefile, O_RDONLY);
+               }
        }
        if (fd == -1)
                return -1;