mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Add basic fuzzer of the parser.
This commit is contained in:
parent
04293424eb
commit
0ebcca5eb7
67
promql/fuzz.go
Normal file
67
promql/fuzz.go
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
package promql
|
||||||
|
// +build gofuzz
|
||||||
|
|
||||||
|
/* PromQL parser fuzzing instrumentation for use with https://github.com/dvyukov/go-fuzz.
|
||||||
|
*
|
||||||
|
* Fuzz each parser by building appropriately instrumented parser, ex. FuzzParseMetric and execute it with it's
|
||||||
|
*
|
||||||
|
* go-fuzz-build -func FuzzParseMetric -o FuzzParseMetric.zip github.com/prometheus/prometheus/promql
|
||||||
|
*
|
||||||
|
* And then run the tests with the appropriate inputs
|
||||||
|
*
|
||||||
|
* go-fuzz -bin FuzzParseMetric.zip -workdir fuzz-data/ParseMetric
|
||||||
|
*
|
||||||
|
* Further input samples should go in the folders fuzz-data/ParseMetric/corpus.
|
||||||
|
*
|
||||||
|
* Repeat for ParseMetricSeletion, ParseExpr and ParseStmt
|
||||||
|
*/
|
||||||
|
|
||||||
|
const (
|
||||||
|
fuzz_interesting = 1
|
||||||
|
fuzz_meh = 0
|
||||||
|
fuzz_discard = -1
|
||||||
|
)
|
||||||
|
|
||||||
|
// Fuzz the metric parser
|
||||||
|
func FuzzParseMetric(in []byte) int {
|
||||||
|
_, err := ParseMetric(string(in))
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
return fuzz_interesting
|
||||||
|
}
|
||||||
|
|
||||||
|
return fuzz_discard
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fuzz the metric selector parser
|
||||||
|
func FuzzParseMetricSelector(in []byte) int {
|
||||||
|
_, err := ParseMetricSelector(string(in))
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
return fuzz_interesting
|
||||||
|
}
|
||||||
|
|
||||||
|
return fuzz_discard
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fuzz the expression parser
|
||||||
|
func FuzzParseExpr(in []byte) int {
|
||||||
|
_, err := ParseExpr(string(in))
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
return fuzz_interesting
|
||||||
|
}
|
||||||
|
|
||||||
|
return fuzz_discard
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fuzz the parser
|
||||||
|
func FuzzParseStmts(in []byte) int {
|
||||||
|
_, err := ParseStmts(string(in))
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
return fuzz_interesting
|
||||||
|
}
|
||||||
|
|
||||||
|
return fuzz_discard
|
||||||
|
}
|
Loading…
Reference in a new issue