llvm.org GIT mirror llvm / 5efecd1
Fix a use-after-free in `llvm-config`. Summary: This could happen if `GetComponentNames` is true, because `Name` from `VisitComponent` would reference a stack instance of `std::string` in `ComputeLibsForComponents`. Reviewers: beanz Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D14913 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254108 91177308-0d34-0410-b5e6-96231b3b80d8 Richard Diamond 3 years ago
1 changed file(s) with 10 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
5555 /// libraries.
5656 /// \param GetComponentNames - Get the component names instead of the
5757 /// library name.
58 static void VisitComponent(StringRef Name,
58 static void VisitComponent(const std::string& Name,
5959 const StringMap &ComponentMap,
6060 std::set &VisitedComponents,
61 std::vector<StringRef> &RequiredLibs,
61 std::vector<std::string> &RequiredLibs,
6262 bool IncludeNonInstalled, bool GetComponentNames,
6363 const std::string *ActiveLibDir, bool *HasMissing) {
6464 // Lookup the component.
104104 /// \param IncludeNonInstalled - Whether non-installed components should be
105105 /// reported.
106106 /// \param GetComponentNames - True if one would prefer the component names.
107 static std::vector<StringRef>
107 static std::vector<std::string>
108108 ComputeLibsForComponents(const std::vector &Components,
109109 bool IncludeNonInstalled, bool GetComponentNames,
110110 const std::string *ActiveLibDir, bool *HasMissing) {
111 std::vector<StringRef> RequiredLibs;
111 std::vector<std::string> RequiredLibs;
112112 std::set VisitedComponents;
113113
114114 // Build a map of component names to information.
194194
195195 /// \brief Expand the semi-colon delimited LLVM_DYLIB_COMPONENTS into
196196 /// the full list of components.
197 std::vector GetAllDyLibComponents(const bool IsInDevelopmentTree,
198 const bool GetComponentNames) {
197 std::vector GetAllDyLibComponents(const bool IsInDevelopmentTree,
198 const bool GetComponentNames) {
199199 std::vector DyLibComponents;
200200
201201 StringRef DyLibComponentsStr(LLVM_DYLIB_COMPONENTS);
452452 /// If there are missing static archives and a dylib was
453453 /// built, print LLVM_DYLIB_COMPONENTS instead of everything
454454 /// in the manifest.
455 std::vector<StringRef> Components;
455 std::vector<std::string> Components;
456456 for (unsigned j = 0; j != array_lengthof(AvailableComponents); ++j) {
457457 // Only include non-installed components when in a development tree.
458458 if (!AvailableComponents[j].IsInstalled && !IsInDevelopmentTree)
525525
526526 // Construct the list of all the required libraries.
527527 bool HasMissing = false;
528 std::vector<StringRef> RequiredLibs =
528 std::vector<std::string> RequiredLibs =
529529 ComputeLibsForComponents(Components,
530530 /*IncludeNonInstalled=*/IsInDevelopmentTree,
531531 false, &ActiveLibDir, &HasMissing);
532532
533533 if (PrintSharedMode) {
534534 std::unordered_set FullDyLibComponents;
535 std::vector<StringRef> DyLibComponents =
535 std::vector<std::string> DyLibComponents =
536536 GetAllDyLibComponents(IsInDevelopmentTree, false);
537537
538538 for (auto &Component : DyLibComponents) {
584584 PrintForLib(DyLibName, true);
585585 } else {
586586 for (unsigned i = 0, e = RequiredLibs.size(); i != e; ++i) {
587 StringRef Lib = RequiredLibs[i];
587 auto Lib = RequiredLibs[i];
588588 if (i)
589589 OS << ' ';
590590