Skip to content

Commit

Permalink
statemachine: fix nil dereference
Browse files Browse the repository at this point in the history
  • Loading branch information
valentindavid committed Sep 19, 2023
1 parent f3a3533 commit 49d7d29
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions internal/statemachine/state_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ func (stateMachine *StateMachine) postProcessGadgetYaml() error {
var rootfsSeen bool = false
var farthestOffset quantity.Offset = 0
var lastOffset quantity.Offset = 0
farthestOffsetUnknown := false
var lastVolumeName string
for _, volumeName := range stateMachine.VolumeOrder {
volume := stateMachine.GadgetInfo.Volumes[volumeName]
Expand Down Expand Up @@ -283,10 +284,14 @@ func (stateMachine *StateMachine) postProcessGadgetYaml() error {
}

// update farthestOffset if needed
offset := *structure.Offset
lastOffset = offset + quantity.Offset(structure.Size)
farthestOffset = maxOffset(lastOffset, farthestOffset)
structure.Offset = &offset
if structure.Offset == nil {
farthestOffsetUnknown = true

Check warning on line 288 in internal/statemachine/state_machine.go

View check run for this annotation

Codecov / codecov/patch

internal/statemachine/state_machine.go#L288

Added line #L288 was not covered by tests
} else {
offset := *structure.Offset
lastOffset = offset + quantity.Offset(structure.Size)
farthestOffset = maxOffset(lastOffset, farthestOffset)
structure.Offset = &offset
}

// system-data and system-seed do not always have content defined.
// this makes Content be a nil slice and lead copyStructureContent() skip the rootfs copying later.
Expand All @@ -301,7 +306,7 @@ func (stateMachine *StateMachine) postProcessGadgetYaml() error {
}
}

if !rootfsSeen && len(stateMachine.GadgetInfo.Volumes) == 1 {
if !farthestOffsetUnknown && !rootfsSeen && len(stateMachine.GadgetInfo.Volumes) == 1 {
// We still need to handle the case of unspecified system-data
// partition where we simply attach the rootfs at the end of the
// partition list.
Expand Down

0 comments on commit 49d7d29

Please sign in to comment.