From: Vincent Bernat Date: Tue, 14 May 2013 20:49:48 +0000 (+0200) Subject: lldpcli: don't rely on `fgetln()` providing a NULL-terminated string X-Git-Tag: 0.7.4~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5920dbf73ae170392e43e393e9c1d5983943300f;p=thirdparty%2Flldpd.git lldpcli: don't rely on `fgetln()` providing a NULL-terminated string From the manual page of some BSD, this is not the case. --- diff --git a/src/client/lldpcli.c b/src/client/lldpcli.c index 3547039d..c29853b4 100644 --- a/src/client/lldpcli.c +++ b/src/client/lldpcli.c @@ -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 {