aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_walk.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/cmd_walk.go')
-rw-r--r--internal/game/cmd_walk.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/internal/game/cmd_walk.go b/internal/game/cmd_walk.go
index 101c0fe..c9e7c0a 100644
--- a/internal/game/cmd_walk.go
+++ b/internal/game/cmd_walk.go
@@ -42,16 +42,28 @@ func (g *Game) doWalk(sess *net.Session, args []string) {
func parseWalkDirections(input string) ([]string, error) {
var dirs []string
+ total := 0
+ // maxWalkSteps bounds the slice before it is allocated. Agility caps a
+ // real walk well below this; the limit exists only so a hostile count
+ // like "walk 999999999n" cannot allocate gigabytes on the owner goroutine.
+ const maxWalkSteps = 1000
i := 0
for i < len(input) {
num := 0
for i < len(input) && input[i] >= '0' && input[i] <= '9' {
num = num*10 + int(input[i]-'0')
+ if num > maxWalkSteps {
+ return nil, fmt.Errorf("too many steps at once (limit %d)", maxWalkSteps)
+ }
i++
}
if num == 0 {
num = 1
}
+ total += num
+ if total > maxWalkSteps {
+ return nil, fmt.Errorf("too many steps at once (limit %d)", maxWalkSteps)
+ }
if i >= len(input) {
return nil, fmt.Errorf("unexpected end of directions")
}