Skip to content

Commit 5cdea1f

Browse files
committed
fixup! fix(validator): guard against nil pointer access
1 parent 7be6dba commit 5cdea1f

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

internal/validator/validator.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ func (s *Service) validateApplication(ctx context.Context, app *Application) err
236236
epoch.Index, input.Index, *input.OutputsHash, *epoch.OutputsMerkleRoot)
237237
}
238238

239+
if input.MachineHash == nil {
240+
return s.setApplicationCorrupted(ctx, app,
241+
"inconsistent state: epoch %v last input (%v) machine hash is not defined",
242+
epoch.Index, input.Index)
243+
}
239244
if *epoch.MachineHash != *input.MachineHash {
240245
return s.setApplicationCorrupted(ctx, app,
241246
"epoch %v machine hash does not match epoch last input (%v) machine hash. Expected: %v, Got %v",

internal/validator/validator_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,34 @@ func (s *ValidatorSuite) TestValidateApplicationFailure() {
489489
repo.AssertExpectations(s.T())
490490
})
491491

492+
s.Run("NilInputMachineHash", func() {
493+
input := Input{
494+
EpochApplicationID: app.ID,
495+
OutputsHash: &validator.pristineRootHash,
496+
MachineHash: nil, // <- trigger nil guard
497+
}
498+
499+
repo.On("ListEpochs",
500+
mock.Anything, app.IApplicationAddress.String(), mock.Anything, mock.Anything, false,
501+
).Return([]*Epoch{&dummyEpochs[0]}, uint64(1), nil).Once()
502+
503+
repo.On("ListOutputs",
504+
mock.Anything, mock.Anything, mock.Anything, mock.Anything, false,
505+
).Return([]*Output{}, uint64(0), nil).Once()
506+
507+
repo.On("GetLastInput",
508+
mock.Anything, app.IApplicationAddress.String(), dummyEpochs[0].Index,
509+
).Return(&input, nil).Once()
510+
511+
repo.On("UpdateApplicationStatus",
512+
mock.Anything, mock.Anything, mock.Anything, mock.Anything,
513+
).Return(nil).Once()
514+
515+
err := validator.validateApplication(ctx, &app)
516+
s.NotNil(err)
517+
repo.AssertExpectations(s.T())
518+
})
519+
492520
s.Run("ClaimMismatch", func() {
493521
invalidClaim := common.Hash{}
494522
input := Input{

0 commit comments

Comments
 (0)