@@ -20,10 +20,53 @@ limitations under the License.
20
20
package yaml
21
21
22
22
import (
23
+ "bytes"
24
+
23
25
"gopkg.in/yaml.v2"
26
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24
27
sigyaml "sigs.k8s.io/yaml"
25
28
)
26
29
30
+ // FuzzDurationStrict is a fuzz target for strict-unmarshaling Duration defined
31
+ // in "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 {
35
+ D metav1.Duration `json:"d"`
36
+ }
37
+ if err := sigyaml .UnmarshalStrict (b , & durationHolder ); err != nil {
38
+ return 0
39
+ }
40
+ result , err := sigyaml .Marshal (& durationHolder )
41
+ if err != nil {
42
+ panic (err )
43
+ }
44
+ if ! bytes .Equal (result , b ) {
45
+ panic ("result != input" )
46
+ }
47
+ return 1
48
+ }
49
+
50
+ // FuzzMicroTimeStrict is a fuzz target for strict-unmarshaling MicroTime
51
+ // defined in "k8s.io/apimachinery/pkg/apis/meta/v1". This target also checks
52
+ // that the unmarshaled result can be marshaled back to the input.
53
+ func FuzzMicroTimeStrict (b []byte ) int {
54
+ var microTimeHolder struct {
55
+ T metav1.MicroTime `json:"t"`
56
+ }
57
+ if err := sigyaml .UnmarshalStrict (b , & microTimeHolder ); err != nil {
58
+ return 0
59
+ }
60
+ result , err := sigyaml .Marshal (& microTimeHolder )
61
+ if err != nil {
62
+ panic (err )
63
+ }
64
+ if ! bytes .Equal (result , b ) {
65
+ panic ("result != input" )
66
+ }
67
+ return 1
68
+ }
69
+
27
70
// FuzzSigYaml is a fuzz target for "sigs.k8s.io/yaml" unmarshaling.
28
71
func FuzzSigYaml (b []byte ) int {
29
72
t := struct {}{}
@@ -38,6 +81,26 @@ func FuzzSigYaml(b []byte) int {
38
81
return out
39
82
}
40
83
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.
87
+ func FuzzTime (b []byte ) int {
88
+ var timeHolder struct {
89
+ T metav1.Time `json:"t"`
90
+ }
91
+ if err := sigyaml .UnmarshalStrict (b , & timeHolder ); err != nil {
92
+ return 0
93
+ }
94
+ result , err := sigyaml .Marshal (& timeHolder )
95
+ if err != nil {
96
+ panic (err )
97
+ }
98
+ if ! bytes .Equal (result , b ) {
99
+ panic ("result != input" )
100
+ }
101
+ return 1
102
+ }
103
+
41
104
// FuzzYamlV2 is a fuzz target for "gopkg.in/yaml.v2" unmarshaling.
42
105
func FuzzYamlV2 (b []byte ) int {
43
106
t := struct {}{}
0 commit comments