]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.17] regexp/syntax: reject very deeply nested regexps in Parse
authorRuss Cox <rsc@golang.org>
Wed, 2 Feb 2022 21:41:32 +0000 (16:41 -0500)
committerDmitri Shuralyov <dmitshur@golang.org>
Thu, 17 Feb 2022 19:20:55 +0000 (19:20 +0000)
commitac071634c487eb6ac5422652de3c7c18fba7c522
tree77050dddefc50b3065fddfa8bcab06971e961b14
parentcd6e0d7cad147b686f9f8066b651b0079e6f51c6
[release-branch.go1.17] regexp/syntax: reject very deeply nested regexps in Parse

The regexp code assumes it can recurse over the structure of
a regexp safely. Go's growable stacks make that reasonable
for all plausible regexps, but implausible ones can reach the
“infinite recursion?” stack limit.

This CL limits the depth of any parsed regexp to 1000.
That is, the depth of the parse tree is required to be ≤ 1000.
Regexps that require deeper parse trees will return ErrInternalError.
A future CL will change the error to ErrInvalidDepth,
but using ErrInternalError for now avoids introducing new API
in point releases when this is backported.

Fixes #51112.
Fixes #51118.

Change-Id: I97d2cd82195946eb43a4ea8561f5b95f91fb14c5
Reviewed-on: https://go-review.googlesource.com/c/go/+/384616
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-on: https://go-review.googlesource.com/c/go/+/384854
TryBot-Result: Gopher Robot <gobot@golang.org>
src/regexp/syntax/parse.go
src/regexp/syntax/parse_test.go