Fix truncation problem when reading in long lines. Found by Koen Kooi.
[oweals/opkg-lede.git] / libopkg / pkg_parse.c
index d01dff51dcd192d95dc5def0ca5c4aa32599279b..e0de41f9c55ece8438099eaee6fd60905c29f361 100644 (file)
@@ -351,16 +351,17 @@ pkg_parse_from_stream_nomalloc(pkg_t *pkg, FILE *fp, uint mask,
                        }
 
                        /*
-                        * Realloc and move buf past the data already read.
+                        * Realloc and point buf past the data already read,
+                        * at the NULL terminator inserted by fgets.
                         * |<--------------- buf0len ----------------->|
                         * |                     |<------- buflen ---->|
                         * |---------------------|---------------------|
                         * buf0                   buf
                         */
-                       buflen = buf0len;
+                       buflen = buf0len +1;
                        buf0len *= 2;
                        *buf0 = xrealloc(*buf0, buf0len);
-                       buf = *buf0 + buflen -1;
+                       buf = *buf0 + buflen -2;
 
                        continue;
                }