Skip to content

Commit

Permalink
Fix nil dereferences (#14)
Browse files Browse the repository at this point in the history
* Return before dereferencing nil usmc

* Return before dereferencing nil msg
  • Loading branch information
AndrewFerr authored Nov 13, 2023
1 parent 46d5b4e commit 7125478
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 5 additions & 1 deletion pkg/signalmeow/receiving.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
13 changes: 8 additions & 5 deletions portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 7125478

Please sign in to comment.