[master] d17b812 Limit the number of fields up to 255
Federico G. Schwindt
fgsch at lodoss.net
Fri Jul 28 13:24:16 CEST 2017
commit d17b8129f01350c67cdeb9037b5b4d329532a89c
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date: Fri Jul 28 12:03:52 2017 +0100
Limit the number of fields up to 255
Part of #2344.
diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c
index 04efbda..99413a1 100644
--- a/bin/varnishncsa/varnishncsa.c
+++ b/bin/varnishncsa/varnishncsa.c
@@ -591,8 +591,8 @@ static void
parse_x_format(char *buf)
{
char *e, *r, *s;
+ long lval;
int slt;
- intmax_t i;
if (!strcmp(buf, "Varnish:time_firstbyte")) {
addf_fragment(&CTX.frag[F_ttfb], "");
@@ -632,23 +632,18 @@ parse_x_format(char *buf)
if (r == buf || r[1] == ']')
VUT_Error(1, "Syntax error: VSL:%s", buf);
e[-1] = '\0';
- i = strtoimax(r + 1, &s, 10);
+ lval = strtol(r + 1, &s, 10);
if (s != e - 1)
VUT_Error(1, "Syntax error: VSL:%s]", buf);
- if (i <= 0)
+ if (lval <= 0 || lval > 255) {
VUT_Error(1,
"Syntax error. Field specifier must be"
- " positive: %s]",
+ " between 1 and 255: %s]",
buf);
- if (i > INT_MAX) {
- VUT_Error(1,
- "Field specifier %jd for the tag VSL:%s]"
- " is probably too high",
- i, buf);
}
*r = '\0';
} else
- i = 0;
+ lval = 0;
r = buf;
while (r < e && *r != ':')
r++;
@@ -665,7 +660,7 @@ parse_x_format(char *buf)
VUT_Error(1, "Unknown log tag: %s", buf);
assert(slt >= 0);
- addf_vsl(slt, i, r);
+ addf_vsl(slt, lval, r);
return;
}
VUT_Error(1, "Unknown formatting extension: %s", buf);
diff --git a/bin/varnishtest/tests/u00003.vtc b/bin/varnishtest/tests/u00003.vtc
index 4b026c7..e824961 100644
--- a/bin/varnishtest/tests/u00003.vtc
+++ b/bin/varnishtest/tests/u00003.vtc
@@ -90,10 +90,10 @@ shell -err -expect "Unknown log tag: Begin[a" \
shell -err -expect "Syntax error: VSL:Begin[a]" \
{varnishncsa -F "%{VSL:Begin[a]}x"}
shell -err -match {Syntax error. (?#
-)Field specifier must be positive: Begin\[0\]} \
+)Field specifier must be between 1 and 255: Begin\[0\]} \
{varnishncsa -F "%{VSL:Begin[0]}x"}
-shell -err -match {Field specifier 999999999999 for the tag (?#
-)VSL:Begin\[999999999999\] is probably too high} \
+shell -err -match {Syntax error. (?#
+)Field specifier must be between 1 and 255: Begin\[999999999999\]} \
{varnishncsa -F "%{VSL:Begin[999999999999]}x"}
shell -err -expect "Can't open format file (No such file or directory)" \
{varnishncsa -f /nonexistent/file}
diff --git a/doc/sphinx/reference/varnishncsa.rst b/doc/sphinx/reference/varnishncsa.rst
index 2f9492f..07a8b79 100644
--- a/doc/sphinx/reference/varnishncsa.rst
+++ b/doc/sphinx/reference/varnishncsa.rst
@@ -184,7 +184,8 @@ Supported formatters are:
The field will, if present, treat the log record as a white
space separated list of fields, and only the nth part of the
- record will be matched against. Fields start counting at 1.
+ record will be matched against. Fields start counting at 1 and
+ run up to 255.
Defaults to '-' when the tag is not seen, the record prefix
does not match or the field is out of bounds. If a tag appears
More information about the varnish-commit
mailing list