]> granicus.if.org Git - handbrake/commitdiff
ports: fix memory corruption in hb_getline
authorJohn Stebbins <jstebbins.hb@gmail.com>
Sun, 6 Jan 2019 20:03:41 +0000 (13:03 -0700)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Mon, 14 Jan 2019 21:36:08 +0000 (13:36 -0800)
libhb/ports.c

index 9f5b403cc37ff5d3fb4756ec2e30d2dff3db1116..da48d5d81c219f7ebbe81835f097e6d56396c0c9 100644 (file)
@@ -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')