Skip to content

Commit

Permalink
fix: nil checks from fuzzers
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Oct 28, 2024
1 parent 2b09a6f commit dd40305
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ func (b *Bundle) Validate() error {
// build creates a valid Bundle by building BundleControl. An error is returned if
// the bundle being built has invalid records.
func (b *Bundle) build() error {
if b == nil {
return nil
}

// Requires a valid BundleHeader
if err := b.BundleHeader.Validate(); err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions bundleHeader.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ func (bh *BundleHeader) String() string {
// Validate performs imagecashletter format rule checks on the record and returns an error if not Validated
// The first error encountered is returned and stops the parsing.
func (bh *BundleHeader) Validate() error {
if bh == nil {
return nil
}
if err := bh.fieldInclusion(); err != nil {
return err
}
Expand Down Expand Up @@ -204,6 +207,9 @@ func (bh *BundleHeader) Validate() error {
// fieldInclusion validate mandatory fields are not default values. If fields are
// invalid the Electronic Exchange will be returned.
func (bh *BundleHeader) fieldInclusion() error {
if bh == nil {
return nil
}
if bh.recordType == "" {
return &FieldError{FieldName: "recordType",
Value: bh.recordType,
Expand Down
6 changes: 5 additions & 1 deletion file.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,11 @@ func (f *File) Create() error {
}

if err := b.build(); err != nil {
return fmt.Errorf("building bundle %s: %w", b.BundleHeader.BundleSequenceNumber, err)
bundleSeq := b.ID
if b.BundleHeader != nil {
bundleSeq = b.BundleHeader.BundleSequenceNumber
}
return fmt.Errorf("building bundle %s: %w", bundleSeq, err)
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/fuzz/testdata/fuzz/FuzzReaderWriterJSON/2024-10-28-1.txt

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions test/fuzz/testdata/fuzz/FuzzReaderWriterJSON/2024-10-28-2.txt

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions test/fuzz/testdata/fuzz/FuzzReaderWriterJSON/2024-10-28-3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("{\"CAshLetters\":[{}]}")
2 changes: 2 additions & 0 deletions test/fuzz/testdata/fuzz/FuzzReaderWriterJSON/2024-10-28-4.txt

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions test/fuzz/testdata/fuzz/FuzzReaderWriterJSON/2024-10-28-5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("{\"CAshLetters\":[{}]}")

0 comments on commit dd40305

Please sign in to comment.