summaryrefslogtreecommitdiffstats
path: root/libhb
diff options
context:
space:
mode:
authorJohn Stebbins <[email protected]>2019-01-06 13:03:41 -0700
committerJohn Stebbins <[email protected]>2019-01-14 13:36:08 -0800
commit31e676d288bb1be2f1d6096b26159ac92c7e143f (patch)
tree26d8405593f824bbc00dd8dc1843e765c8e7dec6 /libhb
parentcb9fa4bf684fe2b721dd41837d0f561f511f5300 (diff)
ports: fix memory corruption in hb_getline
Diffstat (limited to 'libhb')
-rw-r--r--libhb/ports.c10
1 files changed, 7 insertions, 3 deletions
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')