Skip to content

Commit

Permalink
Also check lobbies length in TimeoutPeer store method. (#54)
Browse files Browse the repository at this point in the history
We missed this in our checks
  • Loading branch information
koenbollen authored Sep 6, 2023
1 parent 8c2b172 commit 151ac43
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 7 additions & 5 deletions internal/signaling/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,16 +376,18 @@ func (p *Peer) HandleJoinPacket(ctx context.Context, packet JoinPacket) error {
if packet.Lobby == "" {
return fmt.Errorf("no lobby code supplied")
}
if len(packet.Lobby) > 20 {
return fmt.Errorf("lobby code too long")
}

p.Lobby = packet.Lobby

p.store.Subscribe(ctx, p.Game+p.Lobby+p.ID, p.ForwardMessage)

others, err := p.store.JoinLobby(ctx, p.Game, p.Lobby, p.ID)
others, err := p.store.JoinLobby(ctx, p.Game, packet.Lobby, p.ID)
if err != nil {
return err
}

p.Lobby = packet.Lobby
p.store.Subscribe(ctx, p.Game+p.Lobby+p.ID, p.ForwardMessage)

err = p.Send(ctx, JoinedPacket{
RequestID: packet.RequestID,
Type: "joined",
Expand Down
8 changes: 7 additions & 1 deletion internal/signaling/stores/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,18 @@ func (s *PostgresStore) ListLobbies(ctx context.Context, game, filter string) ([
}

func (s *PostgresStore) TimeoutPeer(ctx context.Context, peerID, secret, gameID string, lobbies []string) error {

if len(peerID) > 20 {
logger := logging.GetLogger(ctx)
logger.Warn("peer id too long", zap.String("peerID", peerID))
return ErrInvalidPeerID
}
for _, lobby := range lobbies {
if len(lobby) > 20 {
logger := logging.GetLogger(ctx)
logger.Warn("lobby code too long", zap.String("lobbyCode", lobby))
return ErrInvalidLobbyCode
}
}

now := util.Now(ctx)
_, err := s.DB.Exec(ctx, `
Expand Down

0 comments on commit 151ac43

Please sign in to comment.