Correctly update the end pointer when we expand the buffer.

From Robert Manner.
This commit is contained in:
Todd C. Miller
2022-03-11 08:00:38 -07:00
parent 6ff33922f4
commit c48c511e91

View File

@@ -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))