File Backported-fix-for-CORE-5474-Restrict-UDF-is-not-eff.patch of Package firebird
From: AlexPeshkoff <peshkoff@mail.ru>
Date: Mon, 6 Feb 2017 20:01:53 +0300
Subject: Backported fix for CORE-5474: 'Restrict UDF' is not effective, because fbudf.so is dynamically linked against libc
Patch-mainline: Not tagged yet (likely 4.0-alpha1 / 3.0.2 / 2.5.7)
Git-commit: 8b2a9cb44bf6055e15f016d70a6842b8ada60375
References: bsc#1023990
---
src/jrd/os/posix/mod_loader.cpp | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/src/jrd/os/posix/mod_loader.cpp b/src/jrd/os/posix/mod_loader.cpp
index 771a034c0fd3..9786881b2161 100644
--- a/src/jrd/os/posix/mod_loader.cpp
+++ b/src/jrd/os/posix/mod_loader.cpp
@@ -28,6 +28,7 @@
#include "firebird.h"
#include "../jrd/os/mod_loader.h"
#include "../../common.h"
+#include "../jrd/os/path_utils.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
@@ -47,14 +48,16 @@
class DlfcnModule : public ModuleLoader::Module
{
public:
- DlfcnModule(void* m)
- : module(m)
+ DlfcnModule(MemoryPool& pool, const Firebird::PathName& aFileName, void* m)
+ : fileName(pool, aFileName),
+ module(m)
{}
~DlfcnModule();
void *findSymbol(const Firebird::string&);
private:
+ Firebird::PathName fileName;
void *module;
};
@@ -95,7 +98,7 @@ ModuleLoader::Module *ModuleLoader::loadModule(const Firebird::PathName& modPath
return 0;
}
- return FB_NEW(*getDefaultMemoryPool()) DlfcnModule(module);
+ return FB_NEW(*getDefaultMemoryPool()) DlfcnModule(*getDefaultMemoryPool(), modPath, module);
}
DlfcnModule::~DlfcnModule()
@@ -113,6 +116,18 @@ void *DlfcnModule::findSymbol(const Firebird::string& symName)
result = dlsym(module, newSym.c_str());
}
+
+#ifdef HAVE_DLADDR
+ if (!PathUtils::isRelative(fileName))
+ {
+ Dl_info info;
+ if (!dladdr(result, &info))
+ return NULL;
+ if (fileName != info.dli_fname)
+ return NULL;
+ }
+#endif
+
return result;
}
--
2.11.1