From a9e715b5c5abb658989846d7a6b5f50fab250957 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Tue, 16 Nov 2021 09:27:49 +0000 Subject: [PATCH] Guard in all key consumers --- federationsender/consumers/keychange.go | 11 +++++------ keyserver/consumers/cross_signing.go | 5 +++++ syncapi/consumers/keychange.go | 5 +++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/federationsender/consumers/keychange.go b/federationsender/consumers/keychange.go index 2c366e501..d5dc595c6 100644 --- a/federationsender/consumers/keychange.go +++ b/federationsender/consumers/keychange.go @@ -84,6 +84,11 @@ func (t *KeyChangeConsumer) onMessage(msg *sarama.ConsumerMessage) error { logrus.WithError(err).Errorf("failed to read device message from key change topic") return nil } + if m.DeviceKeys == nil && m.OutputCrossSigningKeyUpdate == nil { + // This probably shouldn't happen but stops us from panicking if we come + // across an update that doesn't satisfy either types. + return nil + } switch m.Type { case api.TypeCrossSigningUpdate: return t.onCrossSigningMessage(m) @@ -95,12 +100,6 @@ func (t *KeyChangeConsumer) onMessage(msg *sarama.ConsumerMessage) error { } func (t *KeyChangeConsumer) onDeviceKeyMessage(m api.DeviceMessage) error { - if m.DeviceKeys == nil && m.OutputCrossSigningKeyUpdate == nil { - // This probably shouldn't happen but stops us from panicking if we come - // across an update that doesn't satisfy either types. - return nil - } - logger := logrus.WithField("user_id", m.UserID) // only send key change events which originated from us diff --git a/keyserver/consumers/cross_signing.go b/keyserver/consumers/cross_signing.go index f9973ec9f..2ba627976 100644 --- a/keyserver/consumers/cross_signing.go +++ b/keyserver/consumers/cross_signing.go @@ -77,6 +77,11 @@ func (t *OutputCrossSigningKeyUpdateConsumer) onMessage(msg *sarama.ConsumerMess logrus.WithError(err).Errorf("failed to read device message from key change topic") return nil } + if m.OutputCrossSigningKeyUpdate == nil { + // This probably shouldn't happen but stops us from panicking if we come + // across an update that doesn't satisfy either types. + return nil + } switch m.Type { case api.TypeCrossSigningUpdate: return t.onCrossSigningMessage(m) diff --git a/syncapi/consumers/keychange.go b/syncapi/consumers/keychange.go index 1938ff9b0..dfedc6409 100644 --- a/syncapi/consumers/keychange.go +++ b/syncapi/consumers/keychange.go @@ -109,6 +109,11 @@ func (s *OutputKeyChangeEventConsumer) onMessage(msg *sarama.ConsumerMessage) er logrus.WithError(err).Errorf("failed to read device message from key change topic") return nil } + if m.DeviceKeys == nil && m.OutputCrossSigningKeyUpdate == nil { + // This probably shouldn't happen but stops us from panicking if we come + // across an update that doesn't satisfy either types. + return nil + } switch m.Type { case api.TypeCrossSigningUpdate: return s.onCrossSigningMessage(m, msg.Offset, msg.Partition)