Skip to content

Commit 3755e3f

Browse files
authored
Merge pull request #835 from barnabasdomozi/fix_heap_use_after_free
Fix heap use-after-free in shared object loading
2 parents 184947e + e0341a6 commit 3755e3f

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

parser/src/pluginhandler.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,17 @@ void PluginHandler::loadPlugins(std::vector<std::string>& skipParserList_)
5252
skipParserList_.end())
5353
{
5454
std::string dynamicLibraryPath = dirIter->path().string();
55+
int dlopenFlags = RTLD_NOW;
56+
if (filename == "pythonparser")
57+
{
58+
// RTLD_GLOBAL:
59+
// The symbols defined by this shared object will be made available for
60+
// symbol resolution of subsequently loaded shared objects.
61+
dlopenFlags |= RTLD_GLOBAL;
62+
}
63+
5564
_dynamicLibraries[filename] = util::DynamicLibraryPtr(
56-
new util::DynamicLibrary(dynamicLibraryPath));
65+
new util::DynamicLibrary(dynamicLibraryPath, dlopenFlags));
5766
}
5867
else
5968
{

util/include/util/dynamiclibrary.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class DynamicLibrary
2121
{
2222
public:
2323
DynamicLibrary(void* handle_);
24-
DynamicLibrary(const std::string& path_);
24+
DynamicLibrary(const std::string& path_, int dlopen_flags_ = RTLD_NOW);
2525

2626
~DynamicLibrary();
2727

util/src/dynamiclibrary.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ std::string DynamicLibrary::extension()
1616

1717
DynamicLibrary::DynamicLibrary(void* handle_) : _handle(handle_){}
1818

19-
DynamicLibrary::DynamicLibrary(const std::string& path_)
19+
DynamicLibrary::DynamicLibrary(const std::string& path_, int dlopen_flags_)
2020
{
2121
if (path_.empty())
2222
{
@@ -37,7 +37,7 @@ DynamicLibrary::DynamicLibrary(const std::string& path_)
3737
throw std::runtime_error(ss.str());
3838
}
3939
#else
40-
_handle = ::dlopen(path_.c_str(), RTLD_NOW | RTLD_GLOBAL);
40+
_handle = ::dlopen(path_.c_str(), dlopen_flags_);
4141
if (!_handle)
4242
{
4343
const char *dlError = ::dlerror();

0 commit comments

Comments
 (0)