| 167 | } |
| 168 | |
| 169 | void* DlfcnModule::findSymbol(ISC_STATUS* status, const Firebird::string& symName) |
| 170 | { |
| 171 | void* result = dlsym(module, symName.c_str()); |
| 172 | |
| 173 | if (!result) |
| 174 | { |
| 175 | Firebird::string newSym = '_' + symName; |
| 176 | result = dlsym(module, newSym.c_str()); |
| 177 | } |
| 178 | |
| 179 | if (!result) |
| 180 | { |
| 181 | makeErrorStatus(status, dlerror()); |
| 182 | return NULL; |
| 183 | } |
| 184 | |
| 185 | #ifdef HAVE_DLADDR |
| 186 | Dl_info info; |
| 187 | if (!dladdr(result, &info)) |
| 188 | { |
| 189 | makeErrorStatus(status, dlerror()); |
| 190 | return NULL; |
| 191 | } |
| 192 | |
| 193 | const auto& libraryPath = realPath.isEmpty() ? fileName : realPath; |
| 194 | |
| 195 | char symbolPathBuffer[PATH_MAX]; |
| 196 | const char* symbolPath = symbolPathBuffer; |
| 197 | |
| 198 | if (!realpath(info.dli_fname, symbolPathBuffer)) |
| 199 | symbolPath = info.dli_fname; |
| 200 | |
| 201 | const char* errText = "Actual module name does not match requested"; |
| 202 | if (PathUtils::isRelative(libraryPath) || PathUtils::isRelative(symbolPath)) |
| 203 | { |
| 204 | // check only name (not path) of the library |
| 205 | Firebird::PathName dummyDir, nm1, nm2; |
| 206 | PathUtils::splitLastComponent(dummyDir, nm1, libraryPath); |
| 207 | PathUtils::splitLastComponent(dummyDir, nm2, symbolPath); |
| 208 | if (nm1 != nm2) |
| 209 | { |
| 210 | makeErrorStatus(status, errText); |
| 211 | return NULL; |
| 212 | } |
| 213 | } |
| 214 | else if (libraryPath != symbolPath) |
| 215 | { |
| 216 | makeErrorStatus(status, errText); |
| 217 | return NULL; |
| 218 | } |
| 219 | #endif |
| 220 | |
| 221 | return result; |
| 222 | } |
| 223 | |
| 224 | bool DlfcnModule::getRealPath(const Firebird::string& anySymbol, Firebird::PathName& path) |
| 225 | { |
no test coverage detected