[PATCH] D146412: [NFC] Fix potential use-after-free in DumpModuleInfoAction::ExecuteAction()
Mariya Podchishchaeva via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 20 04:09:15 PDT 2023
Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Since each `DumpModuleInfoAction` can now contain a pointer to a
`raw_ostream`, saving there a poiter that owned by a local `unique_ptr`
may cause use-after-free.
Found by static analyzer.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D146412
Files:
clang/lib/Frontend/FrontendActions.cpp
Index: clang/lib/Frontend/FrontendActions.cpp
===================================================================
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -781,13 +781,16 @@
std::unique_ptr<llvm::raw_fd_ostream> OutFile;
CompilerInstance &CI = getCompilerInstance();
StringRef OutputFileName = CI.getFrontendOpts().OutputFile;
+ llvm::raw_ostream *POut = &llvm::outs();
if (!OutputFileName.empty() && OutputFileName != "-") {
std::error_code EC;
OutFile.reset(new llvm::raw_fd_ostream(OutputFileName.str(), EC,
llvm::sys::fs::OF_TextWithCRLF));
- OutputStream = OutFile.get();
+ POut = OutFile.get();
+ } else if (OutputStream) {
+ POut = OutputStream;
}
- llvm::raw_ostream &Out = OutputStream ? *OutputStream : llvm::outs();
+ llvm::raw_ostream &Out = *POut;
Out << "Information for module file '" << getCurrentFile() << "':\n";
auto &FileMgr = CI.getFileManager();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146412.506533.patch
Type: text/x-patch
Size: 1006 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230320/c15ce533/attachment.bin>
More information about the cfe-commits
mailing list