]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lldpcli: don't rely on `fgetln()` providing a NULL-terminated string
authorVincent Bernat <bernat@luffy.cx>
Tue, 14 May 2013 20:49:48 +0000 (22:49 +0200)
committerVincent Bernat <bernat@luffy.cx>
Tue, 14 May 2013 20:49:48 +0000 (22:49 +0200)
From the manual page of some BSD, this is not the case.

src/client/lldpcli.c

index 3547039d54dd105e68d3f1eb25833dc5fe279ff3..c29853b49eb9d41d994cd13f9bbfd657c65f12fc 100644 (file)
@@ -472,10 +472,12 @@ main(int argc, char *argv[])
                        size_t len;
                        char *line;
                        while ((line = fgetln(file, &len))) {
+                               line = strndup(line, len);
                                if (line[len - 1] == '\n') {
                                        line[len - 1] = '\0';
                                        parse_and_exec(conn, fmt, line);
                                }
+                               free(line);
                        }
                        fclose(file);
                } else {