From 7f97fc6a908c57de46279b879882d0edb185715c Mon Sep 17 00:00:00 2001 From: James Jones Date: Mon, 16 Sep 2024 13:54:33 -0500 Subject: [PATCH] Avoid Coverity overflow in write_all() (CID #1604608) Revises write_all() loop analogously to fr_rand_init() loop (CID #1604611) --- src/modules/rlm_mschap/rlm_mschap.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/modules/rlm_mschap/rlm_mschap.c b/src/modules/rlm_mschap/rlm_mschap.c index 520ba73557ba..393974af1f23 100644 --- a/src/modules/rlm_mschap/rlm_mschap.c +++ b/src/modules/rlm_mschap/rlm_mschap.c @@ -836,13 +836,13 @@ static void mppe_add_reply(UNUSED rlm_mschap_t const *inst, */ static int write_all(int fd, char const *buf, size_t len) { ssize_t rv; - size_t done=0; + char const *p = buf; + char const *end = p + len; - while (done < len) { - rv = write(fd, buf+done, len-done); - if (rv <= 0) - break; - done += rv; + while (p < end) { + rv = write(fd, p, (size_t) (end - p)); + if (rv <= 0) break; + p += rv; } rv = write(fd, "\n", 1); if (rv <= 0) return -1;