Skip to content

Commit 7e7f441

Browse files
nixprimegvisor-bot
authored andcommitted
state: fix nil dereference when encodeState.Save() => wire.Save() fails
PiperOrigin-RevId: 839296491
1 parent 86e78c1 commit 7e7f441

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pkg/state/encode.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -802,14 +802,19 @@ func (es *encodeState) Save(obj reflect.Value) {
802802
})
803803
for _, id := range ids {
804804
// Encode the id.
805+
oes = nil
805806
wire.Save(&es.w, wire.Uint(id))
806807
// Marshal the object.
807-
oes := es.pending[id]
808+
oes = es.pending[id]
808809
wire.Save(&es.w, oes.encoded)
809810
}
810811
}); err != nil {
811-
// Include the object and the error.
812-
Failf("error serializing object %#v: %w", oes.encoded, err)
812+
if oes != nil {
813+
// Include the object and the error.
814+
Failf("error serializing object %#v: %w", oes.encoded, err)
815+
} else {
816+
Failf("error serializing type or ID: %w", err)
817+
}
813818
}
814819
}
815820

0 commit comments

Comments
 (0)