Skip to content

[Syntax] Fix use-after-free in SyntaxSerialization #10374

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
Jun 20, 2017

Conversation

harlanhaskins
Copy link
Contributor

@harlanhaskins harlanhaskins commented Jun 19, 2017

The ASAN build caught a use-after-free because the StringRef passed into the JSON output for TriviaPiece was destroyed before the outputting happened. Instead, explicitly copy the OwnedString first. Instead, ensure the string outlives the raw syntax tree by moving the CompilerInstance out of getSyntaxTree.

@harlanhaskins
Copy link
Contributor Author

@swift-ci please ASAN test

@harlanhaskins
Copy link
Contributor Author

@swift-ci please ASAN test

@huonw
Copy link
Contributor

huonw commented Jun 19, 2017

Doesn't this mean the copy of the string leaks? Either that or the copy is destroyed at the end of the statement and asan will fail too?

@harlanhaskins
Copy link
Contributor Author

Yep. I think the main issue is that this string owned by the SourceManager and not the RawSyntax tree.

A more permanent fix would be to ensure the SourceManager lives as long as the RawSyntax tree here.

@harlanhaskins
Copy link
Contributor Author

@swift-ci please ASAN test

@jrose-apple jrose-apple requested review from bitjammer and removed request for jrose-apple June 19, 2017 19:14
@harlanhaskins
Copy link
Contributor Author

Passed ASAN locally.

@swift-ci please ASAN test

Copy link
Contributor

@huonw huonw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to squash the two commits before merging, so that the copying isn't done and then immediately undone.

@harlanhaskins
Copy link
Contributor Author

I squashed those changes 👍

@swift-ci please smoke test and merge

@CodaFi
Copy link
Contributor

CodaFi commented Jun 20, 2017

@swift-ci please smoke test and merge

@harlanhaskins
Copy link
Contributor Author

Uh... @shahmishal:

/home/buildnode/disk2/workspace/swift-PR-Linux-smoke-test/branch-master/swift/utils/build-script-impl: line 261: 18071 Segmentation fault      "$@"

@harlanhaskins
Copy link
Contributor Author

This was after building Foundation.

@harlanhaskins
Copy link
Contributor Author

In the meantime, what's one more test?

@swift-ci please smoke test and merge

@swift-ci swift-ci merged commit 1dea34b into swiftlang:master Jun 20, 2017
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.

4 participants