]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Check fclose(3) writes correctly, thanks to Bob.
authorRoy Marples <roy@marples.name>
Fri, 12 Jun 2015 09:54:09 +0000 (09:54 +0000)
committerRoy Marples <roy@marples.name>
Fri, 12 Jun 2015 09:54:09 +0000 (09:54 +0000)
auth.c
duid.c
ipv6.c

diff --git a/auth.c b/auth.c
index 4bfbfdc587b458c70eb9dbec58483d72a813b7c3..b24f75723c9db6724a757a4ae33cad925adfc7ee 100644 (file)
--- a/auth.c
+++ b/auth.c
@@ -415,7 +415,8 @@ get_next_rdm_monotonic_counter(struct auth *auth)
        rdm++;
        if (fseek(fp, 0, SEEK_SET) == -1 ||
            ftruncate(fileno(fp), 0) == -1 ||
-           fprintf(fp, "0x%016" PRIu64 "\n", rdm) != 19)
+           fprintf(fp, "0x%016" PRIu64 "\n", rdm) != 19 ||
+           fflush(fp) == EOF)
        {
                if (!auth->last_replay_set) {
                        auth->last_replay = rdm;
@@ -424,7 +425,6 @@ get_next_rdm_monotonic_counter(struct auth *auth)
                        rdm = ++auth->last_replay;
                /* report error? */
        }
-       fflush(fp);
 #ifdef LOCK_EX
        if (flocked == 0)
                flock(fileno(fp), LOCK_UN);
diff --git a/duid.c b/duid.c
index d24ebc4723b7ed7c2c7528190f3715a5af71295e..b84c497ee63eb4956a52d122e5bda5e706778b90 100644 (file)
--- a/duid.c
+++ b/duid.c
@@ -140,7 +140,8 @@ duid_get(unsigned char *d, const struct interface *ifp)
        }
        len = duid_make(d, ifp, DUID_LLT);
        x = fprintf(fp, "%s\n", hwaddr_ntoa(d, len, line, sizeof(line)));
-       fclose(fp);
+       if (fclose(fp) == EOF)
+               x = -1;
        /* Failed to write the duid? scrub it, we cannot use it */
        if (x < 1) {
                logger(ifp->ctx, LOG_ERR, "error writing DUID: %s: %m", DUID);
diff --git a/ipv6.c b/ipv6.c
index 00d74b46acaf778d3a2d10e91fa03f03d552ede4..2db5816cee94311100b6dea4640ee2859bdc1024 100644 (file)
--- a/ipv6.c
+++ b/ipv6.c
@@ -251,7 +251,8 @@ ipv6_readsecret(struct dhcpcd_ctx *ctx)
                goto eexit;
        x = fprintf(fp, "%s\n",
            hwaddr_ntoa(ctx->secret, ctx->secret_len, line, sizeof(line)));
-       fclose(fp);
+       if (fclose(fp) == EOF)
+               x = -1;
        if (x > 0)
                return (ssize_t)ctx->secret_len;