Commit d17b8129 authored by Federico G. Schwindt's avatar Federico G. Schwindt

Limit the number of fields up to 255

Part of #2344.
parent 3457dedc
......@@ -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);
......
......@@ -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}
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment