From 02597f15f0b60dbea49f8540c87981f7967d5509 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 6 Jun 2022 08:56:06 +0100 Subject: [PATCH] Fix panic in `QueryRestrictedJoinAllowed` --- roomserver/internal/query/query.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/roomserver/internal/query/query.go b/roomserver/internal/query/query.go index 6d306fb0..da1b3253 100644 --- a/roomserver/internal/query/query.go +++ b/roomserver/internal/query/query.go @@ -778,11 +778,18 @@ func (r *Queryer) QueryRestrictedJoinAllowed(ctx context.Context, req *api.Query } else if !allowRestrictedJoins { return nil } + // Start off by populating the "resident" flag in the response. If we + // come across any rooms in the request that are missing, we will unset + // the flag. + res.Resident = true // Get the join rules to work out if the join rule is "restricted". joinRulesEvent, err := r.DB.GetStateEvent(ctx, req.RoomID, gomatrixserverlib.MRoomJoinRules, "") if err != nil { return fmt.Errorf("r.DB.GetStateEvent: %w", err) } + if joinRulesEvent == nil { + return nil + } var joinRules gomatrixserverlib.JoinRuleContent if err = json.Unmarshal(joinRulesEvent.Content(), &joinRules); err != nil { return fmt.Errorf("json.Unmarshal: %w", err) @@ -792,10 +799,6 @@ func (r *Queryer) QueryRestrictedJoinAllowed(ctx context.Context, req *api.Query if !res.Restricted { return nil } - // Start off by populating the "resident" flag in the response. If we - // come across any rooms in the request that are missing, we will unset - // the flag. - res.Resident = true // If the user is already invited to the room then the join is allowed // but we don't specify an authorised via user, since the event auth // will allow the join anyway.