Skip to content

Fix a stack corruption issue in CFRegularExpression (SR-1003) #301

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

Merged
merged 1 commit into from
Mar 30, 2016
Merged

Fix a stack corruption issue in CFRegularExpression (SR-1003) #301

merged 1 commit into from
Mar 30, 2016

Conversation

pushkarnk
Copy link
Member

This is the proposed fix for https://bugs.swift.org/browse/SR-1003

The function _CFRegularExpressionEnumerateMatchesInString() walks the text
searching for occurrences of the pattern. For every occurrence, it populates
a CFRange array. If the number of capture groups is not greater than 7, it
uses an array on the stack (instead of mallocing one). However, the total
number of CFRanges inserted is (number of capture groups + 1). The last
insert can corrupt the stack if the number of capture groups is 7 and change the
values of other locals leading to unexplained behaviour.

The function _CFRegularExpressionEnumerateMatchesInString() walks the text
searching for occurrences of the pattern. For every occurrence, it populates
a CFRange array. If the number of capture groups is not greater than 7, it
uses an array on the stack (instead of mallocing one). However, the total
number of CFRanges inserted is (number of capture groups + 1). The last
insert can corrupt the stack if the number of capture groups is 7.
@phausler phausler merged commit fc1ef5d into swiftlang:master Mar 30, 2016
@pushkarnk pushkarnk deleted the sr-1003 branch April 12, 2016 13:30
atrick pushed a commit to atrick/swift-corelibs-foundation that referenced this pull request Jan 12, 2021
[gardening] Fix warning about strerror return value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants