The current interface theoretically could lead to a use-after-free when a client holds on to the returned pointer. Ficx this by returning a shared_ptr to the scratch typesystem
rdar://103619233
Paths
| Differential D141100
Return a shared_ptr from ScratchTypeSystemClang::GetForTarget() ClosedPublic Authored by aprantl on Jan 5 2023, 5:01 PM.
Details Summary The current interface theoretically could lead to a use-after-free when a client holds on to the returned pointer. Ficx this by returning a shared_ptr to the scratch typesystem rdar://103619233
Diff Detail
Event TimelineComment Actions LGTM
This revision is now accepted and ready to land.Jan 9 2023, 6:07 AM Comment Actions I don't like how this patch (unintentionally) hides that the returned object is a shared pointer.
Replacing the instances of auto with TypeSystemClangSP would address my concerns. Comment Actions
I'm not familiar with the APIs involved here, but when I read the sentence above, what comes to mind is that the contract of a raw pointer is that a client shouldn't hold it past the lifetime of the object that produced this raw pointer. In fact, all uses updated in this patch seem to respect that. An inspection of the code here seems to indicate that the Target object is the owner of the TypeSystem object. As I said though, I looked at this code for the first time just now, so feel free to ignore it if I'm missing something :) Comment Actions
As much as I dislike the amount of work this is going to be, I actually agree. Comment Actions
Scratch TypeSystems (particularly TypeSystemSwift) can live shorter than their owning Target. Fatal compiler errors can cause them to get torn down and replaced by a new instance.
This revision was landed with ongoing or failed builds.Jan 9 2023, 3:05 PM Closed by commit rGf8d7ab8cf8e8: Return a shared_ptr from ScratchTypeSystemClang::GetForTarget() (authored by aprantl). · Explain Why This revision was automatically updated to reflect the committed changes.
Revision Contents
Diff 487569 lldb/include/lldb/lldb-forward.h
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
lldb/source/Plugins/Language/ObjC/NSArray.cpp
lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
lldb/source/Plugins/Language/ObjC/NSError.cpp
lldb/source/Plugins/Language/ObjC/NSException.cpp
lldb/source/Plugins/Language/ObjC/NSIndexPath.cpp
lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp
lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp
lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp
lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
|
Redundant std::static_pointer_cast?