mirror of
https://github.com/rsmarples/dhcpcd.git
synced 2024-11-28 12:33:49 +08:00
Check fclose(3) writes correctly, thanks to Bob.
This commit is contained in:
parent
a175f2b7dd
commit
32897869f1
4
auth.c
4
auth.c
@ -415,7 +415,8 @@ get_next_rdm_monotonic_counter(struct auth *auth)
|
|||||||
rdm++;
|
rdm++;
|
||||||
if (fseek(fp, 0, SEEK_SET) == -1 ||
|
if (fseek(fp, 0, SEEK_SET) == -1 ||
|
||||||
ftruncate(fileno(fp), 0) == -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) {
|
if (!auth->last_replay_set) {
|
||||||
auth->last_replay = rdm;
|
auth->last_replay = rdm;
|
||||||
@ -424,7 +425,6 @@ get_next_rdm_monotonic_counter(struct auth *auth)
|
|||||||
rdm = ++auth->last_replay;
|
rdm = ++auth->last_replay;
|
||||||
/* report error? */
|
/* report error? */
|
||||||
}
|
}
|
||||||
fflush(fp);
|
|
||||||
#ifdef LOCK_EX
|
#ifdef LOCK_EX
|
||||||
if (flocked == 0)
|
if (flocked == 0)
|
||||||
flock(fileno(fp), LOCK_UN);
|
flock(fileno(fp), LOCK_UN);
|
||||||
|
3
duid.c
3
duid.c
@ -140,7 +140,8 @@ duid_get(unsigned char *d, const struct interface *ifp)
|
|||||||
}
|
}
|
||||||
len = duid_make(d, ifp, DUID_LLT);
|
len = duid_make(d, ifp, DUID_LLT);
|
||||||
x = fprintf(fp, "%s\n", hwaddr_ntoa(d, len, line, sizeof(line)));
|
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 */
|
/* Failed to write the duid? scrub it, we cannot use it */
|
||||||
if (x < 1) {
|
if (x < 1) {
|
||||||
logger(ifp->ctx, LOG_ERR, "error writing DUID: %s: %m", DUID);
|
logger(ifp->ctx, LOG_ERR, "error writing DUID: %s: %m", DUID);
|
||||||
|
3
ipv6.c
3
ipv6.c
@ -251,7 +251,8 @@ ipv6_readsecret(struct dhcpcd_ctx *ctx)
|
|||||||
goto eexit;
|
goto eexit;
|
||||||
x = fprintf(fp, "%s\n",
|
x = fprintf(fp, "%s\n",
|
||||||
hwaddr_ntoa(ctx->secret, ctx->secret_len, line, sizeof(line)));
|
hwaddr_ntoa(ctx->secret, ctx->secret_len, line, sizeof(line)));
|
||||||
fclose(fp);
|
if (fclose(fp) == EOF)
|
||||||
|
x = -1;
|
||||||
if (x > 0)
|
if (x > 0)
|
||||||
return (ssize_t)ctx->secret_len;
|
return (ssize_t)ctx->secret_len;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user