0
0
Fork 0
mirror of https://github.com/matrix-org/dendrite synced 2024-12-14 17:23:52 +01:00

Fix a panic in OnIncomingMessagesRequest (#2250)

It's possible for `GetStateEvent` to return `nil` if there was no error but the state event wasn't found. Therefore we need to be prepared for that case.

This should fix #2247.
This commit is contained in:
Neil Alexander 2022-03-04 10:24:26 +00:00 committed by GitHub
parent f75169c353
commit 7fc62d8178
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -184,16 +184,18 @@ func OnIncomingMessagesRequest(
// at least fetch the membership events for the users returned in chunk if LazyLoadMembers is set // at least fetch the membership events for the users returned in chunk if LazyLoadMembers is set
state := []gomatrixserverlib.ClientEvent{} state := []gomatrixserverlib.ClientEvent{}
if filter.LazyLoadMembers { if filter.LazyLoadMembers {
memberShipToUser := make(map[string]*gomatrixserverlib.HeaderedEvent) membershipToUser := make(map[string]*gomatrixserverlib.HeaderedEvent)
for _, evt := range clientEvents { for _, evt := range clientEvents {
memberShip, err := db.GetStateEvent(req.Context(), roomID, gomatrixserverlib.MRoomMember, evt.Sender) membership, err := db.GetStateEvent(req.Context(), roomID, gomatrixserverlib.MRoomMember, evt.Sender)
if err != nil { if err != nil {
util.GetLogger(req.Context()).WithError(err).Error("failed to get membership event for user") util.GetLogger(req.Context()).WithError(err).Error("failed to get membership event for user")
continue continue
} }
memberShipToUser[evt.Sender] = memberShip if membership != nil {
membershipToUser[evt.Sender] = membership
} }
for _, evt := range memberShipToUser { }
for _, evt := range membershipToUser {
state = append(state, gomatrixserverlib.HeaderedToClientEvent(evt, gomatrixserverlib.FormatAll)) state = append(state, gomatrixserverlib.HeaderedToClientEvent(evt, gomatrixserverlib.FormatAll))
} }
} }