Skip to content

Commit

Permalink
Avoid Coverity overflow in write_all() (CID #1604608)
Browse files Browse the repository at this point in the history
Revises write_all() loop analogously to fr_rand_init() loop
(CID #1604611)
  • Loading branch information
jejones3141 committed Sep 16, 2024
1 parent 184dfc8 commit 7f97fc6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/modules/rlm_mschap/rlm_mschap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7f97fc6

Please sign in to comment.