@@ -27,40 +27,42 @@ import (
27
27
sigyaml "sigs.k8s.io/yaml"
28
28
)
29
29
30
- // FuzzDuration is a fuzz target for unmarshaling Duration defined in "k8s.io/apimachinery/pkg/apis/meta/v1".
31
- // This target also checks that the unmarshaled result can be marshaled back to the input.
32
- func FuzzDuration (b []byte ) int {
33
- var unmarshalResult struct {
30
+ // FuzzDuration is a fuzz target for strict-unmarshaling Duration defined in
31
+ // "k8s.io/apimachinery/pkg/apis/meta/v1". This target also checks that the
32
+ // unmarshaled result can be marshaled back to the input.
33
+ func FuzzDurationStrict (b []byte ) int {
34
+ var durationHolder struct {
34
35
D metav1.Duration `json:"d"`
35
36
}
36
- if err := yaml . Unmarshal (b , & unmarshalResult ); err != nil {
37
+ if err := sigyaml . UnmarshalStrict (b , & durationHolder ); err != nil {
37
38
return 0
38
39
}
39
- marshalResult , err := sigyaml .Marshal (& unmarshalResult )
40
+ result , err := sigyaml .Marshal (& durationHolder )
40
41
if err != nil {
41
42
panic (err )
42
43
}
43
- if ! bytes .Equal (marshalResult , b ) {
44
- panic ("marshalResult != input" )
44
+ if ! bytes .Equal (result , b ) {
45
+ panic ("result != input" )
45
46
}
46
47
return 1
47
48
}
48
49
49
- // FuzzMicroTime is a fuzz target for unmarshaling MicroTime defined in "k8s.io/apimachinery/pkg/apis/meta/v1".
50
- // This target also checks that the unmarshaled result can be marshaled back to the input.
51
- func FuzzMicroTime (b []byte ) int {
52
- var unmarshalResult struct {
50
+ // FuzzMicroTime is a fuzz target for strict-unmarshaling MicroTime defined in
51
+ // "k8s.io/apimachinery/pkg/apis/meta/v1". This target also checks that the
52
+ // unmarshaled result can be marshaled back to the input.
53
+ func FuzzMicroTimeStrict (b []byte ) int {
54
+ var microTimeHolder struct {
53
55
T metav1.MicroTime `json:"t"`
54
56
}
55
- if err := yaml . Unmarshal (b , & unmarshalResult ); err != nil {
57
+ if err := sigyaml . UnmarshalStrict (b , & microTimeHolder ); err != nil {
56
58
return 0
57
59
}
58
- marshalResult , err := sigyaml .Marshal (& unmarshalResult )
60
+ result , err := sigyaml .Marshal (& microTimeHolder )
59
61
if err != nil {
60
62
panic (err )
61
63
}
62
- if ! bytes .Equal (marshalResult , b ) {
63
- panic ("marshalResult != input" )
64
+ if ! bytes .Equal (result , b ) {
65
+ panic ("result != input" )
64
66
}
65
67
return 1
66
68
}
@@ -79,21 +81,22 @@ func FuzzSigYaml(b []byte) int {
79
81
return out
80
82
}
81
83
82
- // FuzzTime is a fuzz target for unmarshaling Time defined in "k8s.io/apimachinery/pkg/apis/meta/v1".
83
- // This target also checks that the unmarshaled result can be marshaled back to the input.
84
+ // FuzzTime is a fuzz target for strict-unmarshaling Time defined in
85
+ // "k8s.io/apimachinery/pkg/apis/meta/v1". This target also checks that the
86
+ // unmarshaled result can be marshaled back to the input.
84
87
func FuzzTime (b []byte ) int {
85
- var unmarshalResult struct {
88
+ var timeHolder struct {
86
89
T metav1.Time `json:"t"`
87
90
}
88
- if err := sigyaml .Unmarshal (b , & unmarshalResult ); err != nil {
91
+ if err := sigyaml .UnmarshalStrict (b , & timeHolder ); err != nil {
89
92
return 0
90
93
}
91
- marshalResult , err := yaml .Marshal (& unmarshalResult )
94
+ result , err := sigyaml .Marshal (& timeHolder )
92
95
if err != nil {
93
96
panic (err )
94
97
}
95
- if ! bytes .Equal (marshalResult , b ) {
96
- panic ("marshalResult != input" )
98
+ if ! bytes .Equal (result , b ) {
99
+ panic ("result != input" )
97
100
}
98
101
return 1
99
102
}
0 commit comments