From 8958a57999eed54c7bcd00bc19dccbd4bf9254c1 Mon Sep 17 00:00:00 2001 From: Morten Siebuhr Date: Thu, 30 Jul 2015 22:20:09 +0200 Subject: [PATCH] Fuzzer for the text parser. --- text/fuzz.go | 36 +++++++++++++++++++++++ text/fuzz/corpus/from_test_parse_0 | 2 ++ text/fuzz/corpus/from_test_parse_1 | 6 ++++ text/fuzz/corpus/from_test_parse_2 | 12 ++++++++ text/fuzz/corpus/from_test_parse_3 | 22 ++++++++++++++ text/fuzz/corpus/from_test_parse_4 | 10 +++++++ text/fuzz/corpus/from_test_parse_error_0 | 1 + text/fuzz/corpus/from_test_parse_error_1 | 1 + text/fuzz/corpus/from_test_parse_error_10 | 1 + text/fuzz/corpus/from_test_parse_error_11 | 1 + text/fuzz/corpus/from_test_parse_error_12 | 3 ++ text/fuzz/corpus/from_test_parse_error_13 | 3 ++ text/fuzz/corpus/from_test_parse_error_14 | 3 ++ text/fuzz/corpus/from_test_parse_error_15 | 2 ++ text/fuzz/corpus/from_test_parse_error_16 | 2 ++ text/fuzz/corpus/from_test_parse_error_17 | 1 + text/fuzz/corpus/from_test_parse_error_18 | 1 + text/fuzz/corpus/from_test_parse_error_19 | 3 ++ text/fuzz/corpus/from_test_parse_error_2 | 3 ++ text/fuzz/corpus/from_test_parse_error_3 | 1 + text/fuzz/corpus/from_test_parse_error_4 | 1 + text/fuzz/corpus/from_test_parse_error_5 | 1 + text/fuzz/corpus/from_test_parse_error_6 | 1 + text/fuzz/corpus/from_test_parse_error_7 | 3 ++ text/fuzz/corpus/from_test_parse_error_8 | 1 + text/fuzz/corpus/from_test_parse_error_9 | 1 + text/fuzz/corpus/minimal | 1 + 27 files changed, 123 insertions(+) create mode 100644 text/fuzz.go create mode 100644 text/fuzz/corpus/from_test_parse_0 create mode 100644 text/fuzz/corpus/from_test_parse_1 create mode 100644 text/fuzz/corpus/from_test_parse_2 create mode 100644 text/fuzz/corpus/from_test_parse_3 create mode 100644 text/fuzz/corpus/from_test_parse_4 create mode 100644 text/fuzz/corpus/from_test_parse_error_0 create mode 100644 text/fuzz/corpus/from_test_parse_error_1 create mode 100644 text/fuzz/corpus/from_test_parse_error_10 create mode 100644 text/fuzz/corpus/from_test_parse_error_11 create mode 100644 text/fuzz/corpus/from_test_parse_error_12 create mode 100644 text/fuzz/corpus/from_test_parse_error_13 create mode 100644 text/fuzz/corpus/from_test_parse_error_14 create mode 100644 text/fuzz/corpus/from_test_parse_error_15 create mode 100644 text/fuzz/corpus/from_test_parse_error_16 create mode 100644 text/fuzz/corpus/from_test_parse_error_17 create mode 100644 text/fuzz/corpus/from_test_parse_error_18 create mode 100644 text/fuzz/corpus/from_test_parse_error_19 create mode 100644 text/fuzz/corpus/from_test_parse_error_2 create mode 100644 text/fuzz/corpus/from_test_parse_error_3 create mode 100644 text/fuzz/corpus/from_test_parse_error_4 create mode 100644 text/fuzz/corpus/from_test_parse_error_5 create mode 100644 text/fuzz/corpus/from_test_parse_error_6 create mode 100644 text/fuzz/corpus/from_test_parse_error_7 create mode 100644 text/fuzz/corpus/from_test_parse_error_8 create mode 100644 text/fuzz/corpus/from_test_parse_error_9 create mode 100644 text/fuzz/corpus/minimal diff --git a/text/fuzz.go b/text/fuzz.go new file mode 100644 index 0000000..2fbf0d2 --- /dev/null +++ b/text/fuzz.go @@ -0,0 +1,36 @@ +// Copyright 2014 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package text + +import "bytes" + +// Build only when actually fuzzing +// +build gofuzz + +// Fuzz text metric parser with with github.com/dvyukov/go-fuzz: +// +// go-fuzz-build github.com/prometheus/client_golang/text +// go-fuzz -bin text-fuzz.zip -workdir fuzz +// +// Further input samples should go in the folder fuzz/corpus. +func Fuzz(in []byte) int { + parser := Parser{} + _, err := parser.TextToMetricFamilies(bytes.NewReader(in)) + + if err != nil { + return 0 + } + + return 1 +} diff --git a/text/fuzz/corpus/from_test_parse_0 b/text/fuzz/corpus/from_test_parse_0 new file mode 100644 index 0000000..139597f --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_0 @@ -0,0 +1,2 @@ + + diff --git a/text/fuzz/corpus/from_test_parse_1 b/text/fuzz/corpus/from_test_parse_1 new file mode 100644 index 0000000..2ae8706 --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_1 @@ -0,0 +1,6 @@ + +minimal_metric 1.234 +another_metric -3e3 103948 +# Even that: +no_labels{} 3 +# HELP line for non-existing metric will be ignored. diff --git a/text/fuzz/corpus/from_test_parse_2 b/text/fuzz/corpus/from_test_parse_2 new file mode 100644 index 0000000..5c351db --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_2 @@ -0,0 +1,12 @@ + +# A normal comment. +# +# TYPE name counter +name{labelname="val1",basename="basevalue"} NaN +name {labelname="val2",basename="base\"v\\al\nue"} 0.23 1234567890 +# HELP name two-line\n doc str\\ing + + # HELP name2 doc str"ing 2 + # TYPE name2 gauge +name2{labelname="val2" ,basename = "basevalue2" } +Inf 54321 +name2{ labelname = "val1" , }-Inf diff --git a/text/fuzz/corpus/from_test_parse_3 b/text/fuzz/corpus/from_test_parse_3 new file mode 100644 index 0000000..0b3c345 --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_3 @@ -0,0 +1,22 @@ + +# TYPE my_summary summary +my_summary{n1="val1",quantile="0.5"} 110 +decoy -1 -2 +my_summary{n1="val1",quantile="0.9"} 140 1 +my_summary_count{n1="val1"} 42 +# Latest timestamp wins in case of a summary. +my_summary_sum{n1="val1"} 4711 2 +fake_sum{n1="val1"} 2001 +# TYPE another_summary summary +another_summary_count{n2="val2",n1="val1"} 20 +my_summary_count{n2="val2",n1="val1"} 5 5 +another_summary{n1="val1",n2="val2",quantile=".3"} -1.2 +my_summary_sum{n1="val2"} 08 15 +my_summary{n1="val3", quantile="0.2"} 4711 + my_summary{n1="val1",n2="val2",quantile="-12.34",} NaN +# some +# funny comments +# HELP +# HELP +# HELP my_summary +# HELP my_summary diff --git a/text/fuzz/corpus/from_test_parse_4 b/text/fuzz/corpus/from_test_parse_4 new file mode 100644 index 0000000..bde0a38 --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_4 @@ -0,0 +1,10 @@ + +# HELP request_duration_microseconds The response latency. +# TYPE request_duration_microseconds histogram +request_duration_microseconds_bucket{le="100"} 123 +request_duration_microseconds_bucket{le="120"} 412 +request_duration_microseconds_bucket{le="144"} 592 +request_duration_microseconds_bucket{le="172.8"} 1524 +request_duration_microseconds_bucket{le="+Inf"} 2693 +request_duration_microseconds_sum 1.7560473e+06 +request_duration_microseconds_count 2693 diff --git a/text/fuzz/corpus/from_test_parse_error_0 b/text/fuzz/corpus/from_test_parse_error_0 new file mode 100644 index 0000000..4c67f9a --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_error_0 @@ -0,0 +1 @@ +bla 3.14 \ No newline at end of file diff --git a/text/fuzz/corpus/from_test_parse_error_1 b/text/fuzz/corpus/from_test_parse_error_1 new file mode 100644 index 0000000..b853478 --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_error_1 @@ -0,0 +1 @@ +metric{label="\t"} 3.14 \ No newline at end of file diff --git a/text/fuzz/corpus/from_test_parse_error_10 b/text/fuzz/corpus/from_test_parse_error_10 new file mode 100644 index 0000000..b5fe5f5 --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_error_10 @@ -0,0 +1 @@ +metric{label="bla"} 3.14 2 3 diff --git a/text/fuzz/corpus/from_test_parse_error_11 b/text/fuzz/corpus/from_test_parse_error_11 new file mode 100644 index 0000000..57c7fbc --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_error_11 @@ -0,0 +1 @@ +metric{label="bla"} blubb diff --git a/text/fuzz/corpus/from_test_parse_error_12 b/text/fuzz/corpus/from_test_parse_error_12 new file mode 100644 index 0000000..0a9df79 --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_error_12 @@ -0,0 +1,3 @@ + +# HELP metric one +# HELP metric two diff --git a/text/fuzz/corpus/from_test_parse_error_13 b/text/fuzz/corpus/from_test_parse_error_13 new file mode 100644 index 0000000..5bc7427 --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_error_13 @@ -0,0 +1,3 @@ + +# TYPE metric counter +# TYPE metric untyped diff --git a/text/fuzz/corpus/from_test_parse_error_14 b/text/fuzz/corpus/from_test_parse_error_14 new file mode 100644 index 0000000..a9a2426 --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_error_14 @@ -0,0 +1,3 @@ + +metric 4.12 +# TYPE metric counter diff --git a/text/fuzz/corpus/from_test_parse_error_15 b/text/fuzz/corpus/from_test_parse_error_15 new file mode 100644 index 0000000..7e95ca8 --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_error_15 @@ -0,0 +1,2 @@ + +# TYPE metric bla diff --git a/text/fuzz/corpus/from_test_parse_error_16 b/text/fuzz/corpus/from_test_parse_error_16 new file mode 100644 index 0000000..7825f88 --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_error_16 @@ -0,0 +1,2 @@ + +# TYPE met-ric diff --git a/text/fuzz/corpus/from_test_parse_error_17 b/text/fuzz/corpus/from_test_parse_error_17 new file mode 100644 index 0000000..8f35cae --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_error_17 @@ -0,0 +1 @@ +@invalidmetric{label="bla"} 3.14 2 \ No newline at end of file diff --git a/text/fuzz/corpus/from_test_parse_error_18 b/text/fuzz/corpus/from_test_parse_error_18 new file mode 100644 index 0000000..7ca2cc2 --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_error_18 @@ -0,0 +1 @@ +{label="bla"} 3.14 2 \ No newline at end of file diff --git a/text/fuzz/corpus/from_test_parse_error_19 b/text/fuzz/corpus/from_test_parse_error_19 new file mode 100644 index 0000000..7a6ccc0 --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_error_19 @@ -0,0 +1,3 @@ + +# TYPE metric histogram +metric_bucket{le="bla"} 3.14 diff --git a/text/fuzz/corpus/from_test_parse_error_2 b/text/fuzz/corpus/from_test_parse_error_2 new file mode 100644 index 0000000..726d001 --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_error_2 @@ -0,0 +1,3 @@ + +metric{label="new +line"} 3.14 diff --git a/text/fuzz/corpus/from_test_parse_error_3 b/text/fuzz/corpus/from_test_parse_error_3 new file mode 100644 index 0000000..6aa9e30 --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_error_3 @@ -0,0 +1 @@ +metric{@="bla"} 3.14 \ No newline at end of file diff --git a/text/fuzz/corpus/from_test_parse_error_4 b/text/fuzz/corpus/from_test_parse_error_4 new file mode 100644 index 0000000..d112cb9 --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_error_4 @@ -0,0 +1 @@ +metric{__name__="bla"} 3.14 \ No newline at end of file diff --git a/text/fuzz/corpus/from_test_parse_error_5 b/text/fuzz/corpus/from_test_parse_error_5 new file mode 100644 index 0000000..b34554a --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_error_5 @@ -0,0 +1 @@ +metric{label+="bla"} 3.14 \ No newline at end of file diff --git a/text/fuzz/corpus/from_test_parse_error_6 b/text/fuzz/corpus/from_test_parse_error_6 new file mode 100644 index 0000000..c4d7df3 --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_error_6 @@ -0,0 +1 @@ +metric{label=bla} 3.14 \ No newline at end of file diff --git a/text/fuzz/corpus/from_test_parse_error_7 b/text/fuzz/corpus/from_test_parse_error_7 new file mode 100644 index 0000000..97eafc4 --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_error_7 @@ -0,0 +1,3 @@ + +# TYPE metric summary +metric{quantile="bla"} 3.14 diff --git a/text/fuzz/corpus/from_test_parse_error_8 b/text/fuzz/corpus/from_test_parse_error_8 new file mode 100644 index 0000000..fc70649 --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_error_8 @@ -0,0 +1 @@ +metric{label="bla"+} 3.14 \ No newline at end of file diff --git a/text/fuzz/corpus/from_test_parse_error_9 b/text/fuzz/corpus/from_test_parse_error_9 new file mode 100644 index 0000000..57b4879 --- /dev/null +++ b/text/fuzz/corpus/from_test_parse_error_9 @@ -0,0 +1 @@ +metric{label="bla"} 3.14 2.72 diff --git a/text/fuzz/corpus/minimal b/text/fuzz/corpus/minimal new file mode 100644 index 0000000..be1e6a3 --- /dev/null +++ b/text/fuzz/corpus/minimal @@ -0,0 +1 @@ +m{} 0