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);
|
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)
|
if (!hDll)
|
||||||
{
|
{
|
||||||
ErrorMessage(1, dlerror());
|
ErrorMessage(1, dlerror());
|
||||||
|
@ -330,7 +330,7 @@ void *FS_LoadLibrary(const char *dllName)
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
result = LoadLibraryA(dllName);
|
result = LoadLibraryA(dllName);
|
||||||
#else
|
#else
|
||||||
result = dlopen(dllName, 2);
|
result = dlopen(dllName, RTLD_NOW | RTLD_DEEPBIND | RTLD_LOCAL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1067,7 +1067,7 @@ void LoadThisDll(const char *szDllFilename)
|
|||||||
goto IgnoreThisDLL;
|
goto IgnoreThisDLL;
|
||||||
}
|
}
|
||||||
#else // _WIN32
|
#else // _WIN32
|
||||||
void *hDLL = dlopen(szDllFilename, RTLD_NOW);
|
void *hDLL = dlopen(szDllFilename, RTLD_NOW | RTLD_DEEPBIND | RTLD_LOCAL);
|
||||||
if (!hDLL)
|
if (!hDLL)
|
||||||
{
|
{
|
||||||
Con_Printf("LoadLibrary failed on %s: %s\n", szDllFilename, dlerror());
|
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->base = base;
|
||||||
module->size = end - base;
|
module->size = end - base;
|
||||||
module->end = module->base + module->size - 1;
|
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);
|
ProcessModuleData(module);
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ void *GetModuleHandle(const char *name)
|
|||||||
return nullptr;
|
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());
|
//printf("Error:%s\n",dlerror());
|
||||||
// couldn't open this file
|
// couldn't open this file
|
||||||
@ -139,12 +139,12 @@ CSysModule *Sys_LoadModule(const char *pModuleName)
|
|||||||
szCwd[strlen(szCwd) - 1] = '\0';
|
szCwd[strlen(szCwd) - 1] = '\0';
|
||||||
|
|
||||||
_snprintf(szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s/%s", szCwd, pModuleName);
|
_snprintf(szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s/%s", szCwd, pModuleName);
|
||||||
hDLL = dlopen(szAbsoluteModuleName, RTLD_NOW);
|
hDLL = dlopen(szAbsoluteModuleName, RTLD_NOW | RTLD_DEEPBIND | RTLD_LOCAL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_snprintf(szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s", pModuleName);
|
_snprintf(szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s", pModuleName);
|
||||||
hDLL = dlopen(pModuleName, RTLD_NOW);
|
hDLL = dlopen(pModuleName, RTLD_NOW | RTLD_DEEPBIND | RTLD_LOCAL);
|
||||||
}
|
}
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
@ -158,11 +158,11 @@ CSysModule *Sys_LoadModule(const char *pModuleName)
|
|||||||
#elif defined(OSX)
|
#elif defined(OSX)
|
||||||
printf("Error: %s\n", dlerror());
|
printf("Error: %s\n", dlerror());
|
||||||
_snprintf(str, sizeof(str), "%s.dylib", szAbsoluteModuleName);
|
_snprintf(str, sizeof(str), "%s.dylib", szAbsoluteModuleName);
|
||||||
hDLL = dlopen(str, RTLD_NOW);
|
hDLL = dlopen(str, RTLD_NOW | RTLD_DEEPBIND | RTLD_LOCAL);
|
||||||
#else
|
#else
|
||||||
printf("Error: %s\n", dlerror());
|
printf("Error: %s\n", dlerror());
|
||||||
_snprintf(str, sizeof(str), "%s.so", szAbsoluteModuleName);
|
_snprintf(str, sizeof(str), "%s.so", szAbsoluteModuleName);
|
||||||
hDLL = dlopen(str, RTLD_NOW);
|
hDLL = dlopen(str, RTLD_NOW | RTLD_DEEPBIND | RTLD_LOCAL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user