From c48c511e9113d47bd5c7b4f48a217545ffd33b66 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Fri, 11 Mar 2022 08:00:38 -0700 Subject: [PATCH] Correctly update the end pointer when we expand the buffer. From Robert Manner. --- lib/util/getdelim.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/util/getdelim.c b/lib/util/getdelim.c index 3106f8c57..53687a1f8 100644 --- a/lib/util/getdelim.c +++ b/lib/util/getdelim.c @@ -50,13 +50,13 @@ sudo_getdelim(char **buf, size_t *bufsize, int delim, FILE *fp) do { if (cp + 1 >= ep) { - char *tmp = reallocarray(*buf, *bufsize, 2); - if (tmp == NULL) + char *newbuf = reallocarray(*buf, *bufsize, 2); + if (newbuf == NULL) goto bad; *bufsize *= 2; - cp = tmp + (cp - *buf); - ep = cp + *bufsize; - *buf = tmp; + cp = newbuf + (cp - *buf); + ep = newbuf + *bufsize; + *buf = newbuf; } if ((ch = getc(fp)) == EOF) { if (feof(fp))