Skip to content

[clang][modules] Fix use-after-free in header serialization #8951

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
Jul 9, 2024

Conversation

jansvoboda11
Copy link

With the pruning of unused module map files disabled (-fno-modules-prune-non-affecting-module-map-files), HeaderFileInfo no longer gets deserialized before ASTWriter::WriteHeaderSearch(). This function then interleaves the stores of references to KnownHeader with their lazy deserialization. Lazy deserialization may cause reallocation of ModuleMap::Headers entries (including its SmallVector<KnownHeader, 1> values) thus making previously-stored ArrayRef<KnownHeader> dangling. This patch fixes that situation by storing a copy instead.

rdar://128897015

With the pruning of unused module map files disabled
(`-fno-modules-prune-non-affecting-module-map-files`), `HeaderFileInfo`
no longer gets deserialized before `ASTWriter::WriteHeaderSearch()`.
This function then interleaves the stores of references to `KnownHeader`
with their lazy deserialization. Lazy deserialization may cause
reallocation of `ModuleMap::Headers` entries (including its
`SmallVector<KnownHeader, 1>` values) thus making previously-stored
`ArrayRef<KnownHeader>` dangling. This patch fixes that situation by
storing a copy instead.

(cherry picked from commit 0387a86)
@jansvoboda11
Copy link
Author

@swift-ci please test

@jansvoboda11 jansvoboda11 requested a review from cyndyishida July 9, 2024 00:02
@cyndyishida cyndyishida requested a review from fredriss July 9, 2024 14:42
@fredriss fredriss merged commit a41678e into swift/release/6.0 Jul 9, 2024
3 checks passed
@jansvoboda11 jansvoboda11 deleted the jan_svoboda/fix-use-after-free-release branch July 9, 2024 22:00
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