mirror of
https://github.com/moby/moby.git
synced 2026-08-09 01:21:37 +00:00
daemon/logger/jsonfilelog/jsonlog: use native Go fuzzing
Replace go-fuzz-headers with native fuzz parameters. Constructing JSONLogs directly simplifies the fuzz target and also allows exercising a range of valid time.Time values, whereas the previous fuzzer left Created as the zero value. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -2,20 +2,23 @@ package jsonlog
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
fuzz "github.com/AdaLogics/go-fuzz-headers"
|
||||
"time"
|
||||
)
|
||||
|
||||
func FuzzJSONLogsMarshalJSONBuf(f *testing.F) {
|
||||
f.Fuzz(func(t *testing.T, data []byte) {
|
||||
ff := fuzz.NewConsumer(data)
|
||||
l := &JSONLogs{}
|
||||
err := ff.GenerateStruct(l)
|
||||
if err != nil {
|
||||
return
|
||||
f.Fuzz(func(t *testing.T, log []byte, stream string, created int64, rawAttrs []byte) {
|
||||
l := &JSONLogs{
|
||||
Log: log,
|
||||
Stream: stream,
|
||||
Created: time.Unix(0, created),
|
||||
RawAttrs: json.RawMessage(rawAttrs),
|
||||
}
|
||||
// Exercise MarshalJSONBuf with arbitrary inputs. Errors are expected
|
||||
// for some generated times; the fuzz target is only checking that it
|
||||
// doesn't panic.
|
||||
var buf bytes.Buffer
|
||||
l.MarshalJSONBuf(&buf)
|
||||
_ = l.MarshalJSONBuf(&buf)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user