From 6123c0edca1a52f6da4487b055b69b4f9dd7c9c4 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Thu, 11 Nov 2021 14:06:13 +0000 Subject: [PATCH] Handle the case that the join rules are nonsense --- roomserver/internal/perform/perform_join.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/roomserver/internal/perform/perform_join.go b/roomserver/internal/perform/perform_join.go index 7d00287b..e7b41c01 100644 --- a/roomserver/internal/perform/perform_join.go +++ b/roomserver/internal/perform/perform_join.go @@ -244,10 +244,7 @@ func (r *Joiner) performJoinRoomByID( // Check if the room is a restricted room. If so, update the event // builder content. if restricted, roomIDs, rerr := r.checkIfRestrictedJoin(ctx, req); rerr != nil { - return "", "", &rsAPI.PerformError{ - Code: rsAPI.PerformErrorNotAllowed, - Msg: rerr.Error(), - } + return "", "", err } else if restricted { for _, roomID := range roomIDs { if err = r.attemptRestrictedJoinUsingRoomID(ctx, req, roomID, &eb); err == nil { @@ -345,13 +342,19 @@ func (r *Joiner) checkIfRestrictedJoin( // restricted room or not. joinRuleEvent, err := r.DB.GetStateEvent(ctx, req.RoomIDOrAlias, gomatrixserverlib.MRoomJoinRules, "") if err != nil { - return false, nil, fmt.Errorf("r.DB.GetStateEvent: %w", err) + return false, nil, &rsAPI.PerformError{ + Code: rsAPI.PerformErrorNotAllowed, + Msg: fmt.Sprintf("Unable to retrieve the join rules: %s", err), + } } joinRuleContent := &gomatrixserverlib.JoinRuleContent{ JoinRule: gomatrixserverlib.Public, } if err = json.Unmarshal(joinRuleEvent.Content(), &joinRuleContent); err != nil { - return false, nil, fmt.Errorf("json.Unmarshal: %w", err) + return false, nil, &rsAPI.PerformError{ + Code: rsAPI.PerformErrorNotAllowed, + Msg: fmt.Sprintf("The room join rules are invalid: %s", err), + } } roomIDs := make([]string, 0, len(joinRuleContent.Allow)) for _, allowed := range joinRuleContent.Allow {