Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regexp: stack overflow (process exit) handling deeply nested regexp [1.17 backport] #51118

Closed
gopherbot opened this issue Feb 9, 2022 · 3 comments
Labels
CherryPickApproved Used during the release process for point releases FrozenDueToAge Security
Milestone

Comments

@gopherbot
Copy link
Contributor

@ianlancetaylor requested issue #51112 to be considered for backport to the next 1.17 minor release.

@gopherbot Please open backport issues.

Limit regexp recursion to avoid crashing on deeply nested regexp. Per issue description, this should be backported.

@gopherbot gopherbot added the CherryPickCandidate Used during the release process for point releases label Feb 9, 2022
@gopherbot gopherbot added this to the Go1.17.8 milestone Feb 9, 2022
@gopherbot
Copy link
Contributor Author

Change https://go.dev/cl/384854 mentions this issue: [release-branch.go1.17] regexp/syntax: reject very deeply nested regexps in Parse

@dmitshur
Copy link
Contributor

Approving as a security fix. This backport applies to both 1.17 and 1.16.

@dmitshur dmitshur added CherryPickApproved Used during the release process for point releases and removed CherryPickCandidate Used during the release process for point releases labels Feb 16, 2022
@gopherbot
Copy link
Contributor Author

Closed by merging ac07163 to release-branch.go1.17.

gopherbot pushed a commit that referenced this issue Feb 17, 2022
…xps 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 <[email protected]>
Run-TryBot: Russ Cox <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
Reviewed-on: https://go-review.googlesource.com/c/go/+/384854
TryBot-Result: Gopher Robot <[email protected]>
@golang golang locked and limited conversation to collaborators Feb 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CherryPickApproved Used during the release process for point releases FrozenDueToAge Security
Projects
None yet
Development

No branches or pull requests

3 participants