-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Fix a use-after-free crash in ResetObjCLayout #170360
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
Conversation
operator[] can potentially cause reallocation and invalidate live iterators if it's called with a key that isn't present in the DenseMap. Call lookup() instead to prevent the function from inserting new entries into the DenseMap for ObjC classes that don't have any subclasses. rdar://165448332
|
@llvm/pr-subscribers-clang Author: Akira Hatanaka (ahatanak) Changesoperator[] can potentially cause reallocation and invalidate live iterators if it's called with a key that isn't present in the DenseMap. Call lookup() instead to prevent the function from inserting new entries into the DenseMap for ObjC classes that don't have any subclasses. rdar://165448332 Full diff: https://github.com/llvm/llvm-project/pull/170360.diff 1 Files Affected:
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index b359fc8350375..404ce3ffd77c7 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -12040,7 +12040,7 @@ bool ASTContext::mergeExtParameterInfo(
void ASTContext::ResetObjCLayout(const ObjCInterfaceDecl *D) {
if (auto It = ObjCLayouts.find(D); It != ObjCLayouts.end()) {
It->second = nullptr;
- for (auto *SubClass : ObjCSubClasses[D])
+ for (auto *SubClass : ObjCSubClasses.lookup(D))
ResetObjCLayout(SubClass);
}
}
|
|
Without this fix, an ASan-enabled clang detects a use-after-free when compiling the following code: The DenseMap grows from 64 buckets to 128 buckets when |
|
The bug was introduced in f5c5bc5. |
ojhunt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t took me a little why to work out the path to this failure.
We really need a way to make these kinds of errors trigger deterministically (at least in debug builds)
operator[] can potentially cause reallocation and invalidate live iterators if it's called with a key that isn't present in the DenseMap. Call lookup() instead to prevent the function from inserting new entries into the DenseMap for ObjC classes that don't have any subclasses. rdar://165448332
operator[] can potentially cause reallocation and invalidate live iterators if it's called with a key that isn't present in the DenseMap. Call lookup() instead to prevent the function from inserting new entries into the DenseMap for ObjC classes that don't have any subclasses. rdar://165448332
operator[] can potentially cause reallocation and invalidate live iterators if it's called with a key that isn't present in the DenseMap. Call lookup() instead to prevent the function from inserting new entries into the DenseMap for ObjC classes that don't have any subclasses. rdar://165448332
operator[] can potentially cause reallocation and invalidate live iterators if it's called with a key that isn't present in the DenseMap. Call lookup() instead to prevent the function from inserting new entries into the DenseMap for ObjC classes that don't have any subclasses. rdar://165448332
operator[] can potentially cause reallocation and invalidate live iterators if it's called with a key that isn't present in the DenseMap. Call lookup() instead to prevent the function from inserting new entries into the DenseMap for ObjC classes that don't have any subclasses.
rdar://165448332