mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-25 17:30:56 +08:00
ParseDSL recursed on every '(' with no depth or size cap, so a
query of nested parentheses could grow the goroutine stack until
the process died. Cap input at 4 KiB and nesting at 32.
24 lines
609 B
Go
24 lines
609 B
Go
package db
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseDSLRejectsDeepNesting(t *testing.T) {
|
|
deep := strings.Repeat("(", dslMaxDepth+1) + "a" + strings.Repeat(")", dslMaxDepth+1)
|
|
if _, err := ParseDSL(deep); err == nil {
|
|
t.Fatal("deep nesting accepted")
|
|
}
|
|
ok := strings.Repeat("(", dslMaxDepth) + "a" + strings.Repeat(")", dslMaxDepth)
|
|
if _, err := ParseDSL(ok); err != nil {
|
|
t.Fatalf("depth %d refused: %v", dslMaxDepth, err)
|
|
}
|
|
}
|
|
|
|
func TestParseDSLRejectsOversize(t *testing.T) {
|
|
if _, err := ParseDSL(strings.Repeat("a", dslMaxLen+1)); err == nil {
|
|
t.Fatal("oversize query accepted")
|
|
}
|
|
}
|