[master] 1e0bb69 Remove implicit line feed when using formatfile.

Lasse Karstensen lkarsten at varnish-software.com
Mon May 30 13:38:05 CEST 2016


commit 1e0bb6946361937edd0fc5fa382e4827758b6dcf
Author: Lasse Karstensen <lkarsten at varnish-software.com>
Date:   Mon May 30 13:35:53 2016 +0200

    Remove implicit line feed when using formatfile.
    
    Fixes: #1967

diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c
index 5b54ece..086a779 100644
--- a/bin/varnishncsa/varnishncsa.c
+++ b/bin/varnishncsa/varnishncsa.c
@@ -1103,12 +1103,14 @@ read_format(const char *formatfile)
 {
 	FILE *fmtfile;
 	size_t len = 0;
+	int fmtlen;
 	char *fmt = NULL;
 
 	fmtfile = fopen(formatfile, "r");
 	if (fmtfile == NULL)
 		VUT_Error(1, "Can't open format file (%s)", strerror(errno));
-	if (getline(&fmt, &len, fmtfile) == -1) {
+	fmtlen = getline(&fmt, &len, fmtfile);
+	if (fmtlen == -1) {
 		free(fmt);
 		if (feof(fmtfile))
 			VUT_Error(1, "Empty format file");
@@ -1117,6 +1119,8 @@ read_format(const char *formatfile)
 			    strerror(errno));
 	}
 	fclose(fmtfile);
+	if (fmt[fmtlen - 1] == '\n')
+		fmt[fmtlen - 1] = '\0';
 	return (fmt);
 }
 



More information about the varnish-commit mailing list