Skip to content

Commit c717857

Browse files
committed
appstate: only log warnings on error
1 parent 29d8055 commit c717857

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

appstate/decode.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ func (proc *Processor) decodeSnapshot(
280280
var fakeIndexesToRemove map[[32]byte][]byte
281281
var warn []error
282282
warn, err = currentState.updateHash(encryptedMutations, func(indexMAC []byte, maxIndex int) ([]byte, error) {
283-
vm, newIndexMAC, err := proc.evilHackForLIDMutation(ctx, name, indexMAC, encryptedMutations[maxIndex], maxIndex, encryptedMutations, false)
283+
vm, newIndexMAC, err := proc.evilHackForLIDMutation(
284+
ctx, name, indexMAC, encryptedMutations[maxIndex], maxIndex, encryptedMutations, false,
285+
)
284286
if vm != nil && newIndexMAC != nil && len(indexMAC) == 32 {
285287
if fakeIndexesToRemove == nil {
286288
fakeIndexesToRemove = make(map[[32]byte][]byte)
@@ -289,9 +291,6 @@ func (proc *Processor) decodeSnapshot(
289291
}
290292
return vm, err
291293
})
292-
if len(warn) > 0 {
293-
proc.Log.Warnf("Warnings while updating hash for %s: %+v", name, warn)
294-
}
295294
if err != nil {
296295
err = fmt.Errorf("failed to update state hash: %w", err)
297296
return
@@ -300,6 +299,9 @@ func (proc *Processor) decodeSnapshot(
300299
if validateMACs {
301300
_, err = proc.validateSnapshotMAC(ctx, name, currentState, ss.GetKeyID().GetID(), ss.GetMac())
302301
if err != nil {
302+
if len(warn) > 0 {
303+
proc.Log.Warnf("Warnings while updating hash for %s: %+v", name, warn)
304+
}
303305
err = fmt.Errorf("failed to verify snapshot: %w", err)
304306
return
305307
}
@@ -457,7 +459,9 @@ func (proc *Processor) validatePatch(
457459
if vm != nil || err != nil || !allowEvilLIDHack {
458460
return vm, err
459461
}
460-
vm, newIndexMAC, err := proc.evilHackForLIDMutation(ctx, patchName, indexMAC, patch.Mutations[maxIndex], maxIndex, patch.Mutations, true)
462+
vm, newIndexMAC, err := proc.evilHackForLIDMutation(
463+
ctx, patchName, indexMAC, patch.Mutations[maxIndex], maxIndex, patch.Mutations, true,
464+
)
461465
if vm != nil && newIndexMAC != nil && len(indexMAC) == 32 {
462466
if fakeIndexesToRemove == nil {
463467
fakeIndexesToRemove = make(map[[32]byte][]byte)
@@ -466,9 +470,6 @@ func (proc *Processor) validatePatch(
466470
}
467471
return vm, err
468472
})
469-
if len(warn) > 0 {
470-
proc.Log.Warnf("Warnings while updating hash for %s: %+v", patchName, warn)
471-
}
472473
if err != nil {
473474
err = fmt.Errorf("failed to update state hash: %w", err)
474475
return
@@ -523,10 +524,10 @@ func (proc *Processor) DecodePatches(
523524
proc.Log.Warnf("Failed to validate patches for %s: %v (warnings: %+v) - retrying with evil LID hack", list.Name, err, warn)
524525
newState, warn, fakeIndexesToRemove, err = proc.validatePatch(ctx, list.Name, patch, currentState, validateMACs, true)
525526
}
526-
if len(warn) > 0 {
527-
proc.Log.Warnf("Warnings while updating hash for %s: %+v", list.Name, warn)
528-
}
529527
if err != nil {
528+
if len(warn) > 0 {
529+
proc.Log.Warnf("Warnings while updating hash for %s: %+v", list.Name, warn)
530+
}
530531
return
531532
}
532533

0 commit comments

Comments
 (0)