From: Roy Marples Date: Tue, 3 May 2016 12:19:35 +0000 (+0000) Subject: Really fix the TOCTOU error. X-Git-Tag: v6.11.0~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84f88c4e1f04d3d7a2903fc1fd1d4ed3b9e77d07;p=thirdparty%2Fdhcpcd.git Really fix the TOCTOU error. --- diff --git a/dhcp6.c b/dhcp6.c index 391d5c6b..2fc0257b 100644 --- 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;