Codebase list openssl / ea5def1
Extend dladdr() for AIX, consequence from changes for openssl#6368. The shared libraries are now stored as members of archives, as it is usual on AIX. To correctly address this the custom dladdr()-implementation as well as the dlfcn_load() routine need to be able to cope with such a construct: libname.a(libname.so). Signed-off-by: Matthias Kraft <Matthias.Kraft@softwareag.com> Reviewed-by: Andy Polyakov <appro@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/6872) Matthias Kraft authored 5 years ago Andy Polyakov committed 5 years ago
2 changed file(s) with 35 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
106106 # ifdef RTLD_GLOBAL
107107 if (dso->flags & DSO_FLAG_GLOBAL_SYMBOLS)
108108 flags |= RTLD_GLOBAL;
109 # endif
110 # ifdef _AIX
111 if (filename[strlen(filename) - 1] == ')')
112 flags |= RTLD_MEMBER;
109113 # endif
110114 ptr = dlopen(filename, flags);
111115 if (ptr == NULL) {
331335 unsigned int found = 0;
332336 struct ld_info *ldinfos, *next_ldi, *this_ldi;
333337
334 if ((ldinfos = (struct ld_info *)OPENSSL_malloc(DLFCN_LDINFO_SIZE)) == NULL) {
338 if ((ldinfos = OPENSSL_malloc(DLFCN_LDINFO_SIZE)) == NULL) {
335339 errno = ENOMEM;
336340 dl->dli_fname = NULL;
337341 return 0;
358362 || ((addr >= (uintptr_t)this_ldi->ldinfo_dataorg)
359363 && (addr < ((uintptr_t)this_ldi->ldinfo_dataorg +
360364 this_ldi->ldinfo_datasize)))) {
365 char *buffer, *member;
366 size_t buffer_sz, member_len;
367
368 buffer_sz = strlen(this_ldi->ldinfo_filename) + 1;
369 member = this_ldi->ldinfo_filename + buffer_sz;
370 if ((member_len = strlen(member)) > 0)
371 buffer_sz += 1 + member_len + 1;
361372 found = 1;
362 /*
363 * Ignoring the possibility of a member name and just returning
364 * the path name. See docs: sys/ldr.h, loadquery() and
365 * dlopen()/RTLD_MEMBER.
366 */
367 if ((dl->dli_fname =
368 OPENSSL_strdup(this_ldi->ldinfo_filename)) == NULL)
373 if ((buffer = OPENSSL_malloc(buffer_sz)) != NULL) {
374 OPENSSL_strlcpy(buffer, this_ldi->ldinfo_filename, buffer_sz);
375 if (member_len > 0) {
376 /*
377 * Need to respect a possible member name and not just
378 * returning the path name in this case. See docs:
379 * sys/ldr.h, loadquery() and dlopen()/RTLD_MEMBER.
380 */
381 OPENSSL_strlcat(buffer, "(", buffer_sz);
382 OPENSSL_strlcat(buffer, member, buffer_sz);
383 OPENSSL_strlcat(buffer, ")", buffer_sz);
384 }
385 dl->dli_fname = buffer;
386 } else {
369387 errno = ENOMEM;
388 }
370389 } else {
371 next_ldi =
372 (struct ld_info *)((uintptr_t)this_ldi + this_ldi->ldinfo_next);
390 next_ldi = (struct ld_info *)((uintptr_t)this_ldi +
391 this_ldi->ldinfo_next);
373392 }
374393 } while (this_ldi->ldinfo_next && !found);
375394 OPENSSL_free((void *)ldinfos);
4747
4848 static int shlib_load(const char *filename, SHLIB *lib)
4949 {
50 *lib = dlopen(filename, RTLD_GLOBAL | RTLD_LAZY);
50 int dl_flags = (RTLD_GLOBAL|RTLD_LAZY);
51 #ifdef _AIX
52 if (filename[strlen(filename) - 1] == ')')
53 dl_flags |= RTLD_MEMBER;
54 #endif
55 *lib = dlopen(filename, dl_flags);
5156 return *lib == NULL ? 0 : 1;
5257 }
5358