From 71254782af83e08c79bde9053a43a5837ea36880 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Mon, 13 Nov 2023 09:24:10 -0500 Subject: [PATCH] Fix nil dereferences (#14) * Return before dereferencing nil usmc * Return before dereferencing nil msg --- pkg/signalmeow/receiving.go | 6 +++++- portal.go | 13 ++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pkg/signalmeow/receiving.go b/pkg/signalmeow/receiving.go index 6567505f..ba2ac80a 100644 --- a/pkg/signalmeow/receiving.go +++ b/pkg/signalmeow/receiving.go @@ -206,8 +206,12 @@ func incomingRequestHandlerWithDevice(device *Device) web.RequestHandlerFunc { device.IdentityStore, libsignalgo.NewCallbackContext(ctx), ) - if err != nil { + if err != nil || usmc == nil { + if err == nil { + err = fmt.Errorf("usmc is nil") + } zlog.Err(err).Msg("SealedSenderDecryptToUSMC error") + return nil, err } messageType, err := usmc.GetMessageType() diff --git a/portal.go b/portal.go index aaae6da1..ae5535f0 100644 --- a/portal.go +++ b/portal.go @@ -326,16 +326,19 @@ func (portal *Portal) handleMatrixMessage(sender *User, evt *event.Event) { start = time.Now() msg, err := portal.convertMatrixMessage(ctx, sender, evt) - timestamp := *msg.DataMessage.Timestamp - if timestamp == 0 { - timestamp = uint64(start.UnixMilli()) - } - if err != nil { + if err != nil || msg == nil { + if err == nil { + err = fmt.Errorf("msg is nil") + } portal.log.Error().Msgf("Error converting message %s: %v", evt.ID, err) go ms.sendMessageMetrics(evt, err, "Error converting", true) return } + timestamp := *msg.DataMessage.Timestamp + if timestamp == 0 { + timestamp = uint64(start.UnixMilli()) + } timings.convert = time.Since(start) start = time.Now()