mirror of
https://github.com/rehlds/rehlds.git
synced 2024-12-29 08:05:50 +03:00
Make DLL loading more safe
This commit is contained in:
parent
4246a44557
commit
274b80bb93
@ -227,7 +227,7 @@ long CSys::LoadLibrary(char *lib)
|
||||
|
||||
Q_snprintf(absolute_lib, sizeof(absolute_lib), "%s/%s", cwd, lib);
|
||||
|
||||
void *hDll = dlopen(absolute_lib, RTLD_NOW);
|
||||
void *hDll = dlopen(absolute_lib, RTLD_NOW | RTLD_DEEPBIND | RTLD_LOCAL);
|
||||
if (!hDll)
|
||||
{
|
||||
ErrorMessage(1, dlerror());
|
||||
|
@ -330,7 +330,7 @@ void *FS_LoadLibrary(const char *dllName)
|
||||
#ifdef _WIN32
|
||||
result = LoadLibraryA(dllName);
|
||||
#else
|
||||
result = dlopen(dllName, 2);
|
||||
result = dlopen(dllName, RTLD_NOW | RTLD_DEEPBIND | RTLD_LOCAL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1067,7 +1067,7 @@ void LoadThisDll(const char *szDllFilename)
|
||||
goto IgnoreThisDLL;
|
||||
}
|
||||
#else // _WIN32
|
||||
void *hDLL = dlopen(szDllFilename, RTLD_NOW);
|
||||
void *hDLL = dlopen(szDllFilename, RTLD_NOW | RTLD_DEEPBIND | RTLD_LOCAL);
|
||||
if (!hDLL)
|
||||
{
|
||||
Con_Printf("LoadLibrary failed on %s: %s\n", szDllFilename, dlerror());
|
||||
|
@ -232,7 +232,7 @@ bool HIDDEN FillModule(Section *section, Module *module)
|
||||
module->base = base;
|
||||
module->size = end - base;
|
||||
module->end = module->base + module->size - 1;
|
||||
module->handle = (size_t)dlopen(filename, RTLD_NOW); // lock from unloading
|
||||
module->handle = (size_t)dlopen(filename, RTLD_NOW | RTLD_DEEPBIND | RTLD_LOCAL); // lock from unloading
|
||||
|
||||
ProcessModuleData(module);
|
||||
|
||||
|
@ -88,7 +88,7 @@ void *GetModuleHandle(const char *name)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if ((handle = dlopen(name, RTLD_NOW)) == nullptr)
|
||||
if ((handle = dlopen(name, RTLD_NOW | RTLD_DEEPBIND | RTLD_LOCAL)) == nullptr)
|
||||
{
|
||||
//printf("Error:%s\n",dlerror());
|
||||
// couldn't open this file
|
||||
@ -139,12 +139,12 @@ CSysModule *Sys_LoadModule(const char *pModuleName)
|
||||
szCwd[strlen(szCwd) - 1] = '\0';
|
||||
|
||||
_snprintf(szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s/%s", szCwd, pModuleName);
|
||||
hDLL = dlopen(szAbsoluteModuleName, RTLD_NOW);
|
||||
hDLL = dlopen(szAbsoluteModuleName, RTLD_NOW | RTLD_DEEPBIND | RTLD_LOCAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
_snprintf(szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s", pModuleName);
|
||||
hDLL = dlopen(pModuleName, RTLD_NOW);
|
||||
hDLL = dlopen(pModuleName, RTLD_NOW | RTLD_DEEPBIND | RTLD_LOCAL);
|
||||
}
|
||||
#endif // _WIN32
|
||||
|
||||
@ -158,11 +158,11 @@ CSysModule *Sys_LoadModule(const char *pModuleName)
|
||||
#elif defined(OSX)
|
||||
printf("Error: %s\n", dlerror());
|
||||
_snprintf(str, sizeof(str), "%s.dylib", szAbsoluteModuleName);
|
||||
hDLL = dlopen(str, RTLD_NOW);
|
||||
hDLL = dlopen(str, RTLD_NOW | RTLD_DEEPBIND | RTLD_LOCAL);
|
||||
#else
|
||||
printf("Error: %s\n", dlerror());
|
||||
_snprintf(str, sizeof(str), "%s.so", szAbsoluteModuleName);
|
||||
hDLL = dlopen(str, RTLD_NOW);
|
||||
hDLL = dlopen(str, RTLD_NOW | RTLD_DEEPBIND | RTLD_LOCAL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user