From: John Stebbins Date: Sun, 6 Jan 2019 20:03:41 +0000 (-0700) Subject: ports: fix memory corruption in hb_getline X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=31e676d288bb1be2f1d6096b26159ac92c7e143f;p=handbrake ports: fix memory corruption in hb_getline --- diff --git a/libhb/ports.c b/libhb/ports.c index 9f5b403cc..da48d5d81 100644 --- a/libhb/ports.c +++ b/libhb/ports.c @@ -1445,14 +1445,18 @@ size_t hb_getline(char ** lineptr, size_t * n, FILE * fp) p = bufptr; while (c != EOF) { - if ((p - bufptr) > (size - 1)) + if ((p - bufptr) >= (size - 1)) { + char * tmp; size = size + 128; - bufptr = realloc(bufptr, size); - if (bufptr == NULL) + tmp = realloc(bufptr, size); + if (tmp == NULL) { + free(bufptr); return -1; } + p = tmp + (p - bufptr); + bufptr = tmp; } *p++ = c; if (c == '\n')