Skip to content

[Diagnostics] Use constant strings to avoid use after free. #27980

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
Oct 31, 2019

Conversation

drodriguez
Copy link
Contributor

Using std::string in the function signature copies the constant string
into a stack allocated copy, which is the one referenced by the
StringRef that DiagnosticInfo stores. when the stack is abandoned, the
string seems to be modificed in VC++, which makes the test fail in
Windows.

Using const char * in the signature avoids the std::string creation, and
StringRef will refer to the static data instead.

Intreoduced in #27868 and started to fail in https://ci-external.swift.org/job/oss-swift-windows-x86_64/1790

/cc @owenv

Using std::string in the function signature copies the constant string
into a stack allocated copy, which is the one referenced by the
StringRef that DiagnosticInfo stores. when the stack is abandoned, the
string seems to be modificed in VC++, which makes the test fail in
Windows.

Using const char * in the signature avoids the std::string creation, and
StringRef will refer to the static data instead.
@drodriguez drodriguez requested a review from compnerd October 31, 2019 00:09
@drodriguez
Copy link
Contributor Author

(testing locally at the same time)

@swift-ci please test Windows platform

@drodriguez
Copy link
Contributor Author

@swift-ci please smoke test

Copy link
Contributor

@owenv owenv left a comment

Choose a reason for hiding this comment

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

Thanks for catching this, sorry about the breakage @drodriguez !

@drodriguez
Copy link
Contributor Author

@swift-ci please clean test Windows platform

@drodriguez
Copy link
Contributor Author

Is

'swiftbench' /home/buildnode/jenkins/workspace/swift-PR-Linux-smoke-test/branch-master/swift/benchmark: error: package has unsupported layout; modulemap '/home/buildnode/jenkins/workspace/swift-PR-Linux-smoke-test/branch-master/swift/benchmark/utils/LibProc/module.modulemap' should be inside the 'include' directory

a known error?

Seems to be happening also in other PRs, so I doubt is related to this change.

@owenv
Copy link
Contributor

owenv commented Oct 31, 2019

I'm seeing an error from the SourceKitLSPPackageTests that I may have seen flake before. I might be mistaken though

@compnerd
Copy link
Member

@swift-ci please smoke test linux platform

1 similar comment
@DougGregor
Copy link
Member

@swift-ci please smoke test linux platform

@compnerd
Copy link
Member

@swift-ci please smoke test Linux platform

@owenv
Copy link
Contributor

owenv commented Oct 31, 2019

@compnerd I'm pretty sure this is going to fail again, swiftlang/swift-package-manager#2394 should fix the swiftbench issue

@compnerd
Copy link
Member

Please test with following PR:
swiftlang/swift-package-manager#2394

@swift-ci please smoke test Linux platform

@compnerd
Copy link
Member

@swift-ci please smoke test Linux platform

@compnerd compnerd merged commit 1a5a8dd into swiftlang:master Oct 31, 2019
@drodriguez drodriguez deleted the windows-const-is-your-friend branch October 31, 2019 17:46
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.

5 participants