From 02e6d89cc2bde930be36323e626ce54643d56a7f Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sat, 6 Feb 2021 11:49:18 +0000 Subject: [PATCH 1/3] Fix crash in membership updater (#1753) * Fix nil pointer exception in membership updater * goimports --- roomserver/internal/input/input_membership.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/roomserver/internal/input/input_membership.go b/roomserver/internal/input/input_membership.go index bc646c3c6..44435bfd9 100644 --- a/roomserver/internal/input/input_membership.go +++ b/roomserver/internal/input/input_membership.go @@ -107,6 +107,23 @@ func (r *Inputer) updateMembership( return updates, nil } + // In an ideal world, we shouldn't ever have "add" be nil and "remove" be + // set, as this implies that we're deleting a state event without replacing + // it (a thing that ordinarily shouldn't happen in Matrix). However, state + // resets are sadly a thing occasionally and we have to account for that. + // Beforehand there used to be a check here which stopped dead if we hit + // this scenario, but that meant that the membership table got out of sync + // after a state reset, often thinking that the user was still joined to + // the room even though the room state said otherwise, and this would prevent + // the user from being able to attempt to rejoin the room without modifying + // the database. So instead what we'll do is we'll just update the membership + // table to say that the user is "leave" and we'll use the old event to + // avoid nil pointer exceptions on the code path that follows. + if add == nil { + add = remove + newMembership = gomatrixserverlib.Leave + } + mu, err := updater.MembershipUpdater(targetUserNID, r.isLocalTarget(add)) if err != nil { return nil, err From 82df1948588919800866151cde569c726577b0c3 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Sat, 6 Feb 2021 16:56:55 +0000 Subject: [PATCH 2/3] Increase limit --- setup/mscs/msc2946/msc2946.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/setup/mscs/msc2946/msc2946.go b/setup/mscs/msc2946/msc2946.go index 3580d4d2e..694c97322 100644 --- a/setup/mscs/msc2946/msc2946.go +++ b/setup/mscs/msc2946/msc2946.go @@ -46,7 +46,7 @@ const ( // Defaults sets the request defaults func Defaults(r *gomatrixserverlib.MSC2946SpacesRequest) { - r.Limit = 100 + r.Limit = 2000 r.MaxRoomsPerSpace = -1 } @@ -108,9 +108,6 @@ func federatedSpacesHandler( JSON: jsonerror.BadJSON("The request body could not be decoded into valid JSON. " + err.Error()), } } - if r.Limit > 100 { - r.Limit = 100 - } w := walker{ req: &r, rootRoomID: roomID, From 9a199ba179273250330c85f6d543381b2ac1474c Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Sat, 6 Feb 2021 17:05:00 +0000 Subject: [PATCH 3/3] Remove 100 default --- setup/mscs/msc2946/msc2946.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/setup/mscs/msc2946/msc2946.go b/setup/mscs/msc2946/msc2946.go index 694c97322..03af06669 100644 --- a/setup/mscs/msc2946/msc2946.go +++ b/setup/mscs/msc2946/msc2946.go @@ -144,9 +144,6 @@ func spacesHandler( if resErr := chttputil.UnmarshalJSONRequest(req, &r); resErr != nil { return *resErr } - if r.Limit > 100 { - r.Limit = 100 - } w := walker{ req: &r, rootRoomID: roomID,