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:
Sebastiaan van Stijn
2026-07-10 21:41:56 +02:00
parent 149873ff1d
commit 0015de4032

View File

@@ -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)
})
}