Hi,
I found something that seems to be a bug in ld.so. If I load a
shared library with full path with dlopen, it does not check if the
library is already loaded. I was hoping someone can have a look at
it too, I might have missed something.
This is my first patch, I hope I did not make too much mistakes, I've
read the style guide and tried to follow it.
Best regards,
Peter
Index: library_subr.c
===================================================================
RCS file: /cvs/src/libexec/ld.so/library_subr.c,v
retrieving revision 1.44
diff -u -p -r1.44 library_subr.c
--- library_subr.c 10 Jun 2015 21:16:41 -0000 1.44
+++ library_subr.c 16 Oct 2015 14:02:39 -0000
@@ -302,38 +302,43 @@ _dl_find_loaded_shlib(const char *req_na
elf_object_t *
-_dl_load_shlib(const char *libname, elf_object_t *parent, int type, int flags)
+_dl_load_shlib(const char *full_libname, elf_object_t *parent, int type, int
flags)
{
int try_any_minor, ignore_hints;
struct sod sod, req_sod;
elf_object_t *object = NULL;
char *hint;
+ const char *libname, *last_slash_position;
try_any_minor = 0;
ignore_hints = 0;
+ libname = full_libname;
+ last_slash_position = _dl_strrchr(libname, '/');
- if (_dl_strchr(libname, '/')) {
+ if (last_slash_position != NULL)
+ libname = last_slash_position + 1;
+
+ if (*libname == '\0') {
+ _dl_errno = DL_NOT_FOUND;
+ return NULL;
+ }
+
+ _dl_build_sod(libname, &sod);
+ req_sod = sod;
+
+ object = _dl_find_loaded_shlib(libname, req_sod, flags);
+ if (object) {
+ _dl_free((char *)sod.sod_name);
+ return (object);
+ }
+
+ if (last_slash_position != NULL) {
char *paths[2];
- char *lpath, *lname;
- lpath = _dl_strdup(libname);
+ char *lpath;
+ lpath = _dl_strdup(full_libname);
if (lpath == NULL)
_dl_exit(5);
- lname = _dl_strrchr(lpath, '/');
- if (lname == NULL) {
- _dl_free(lpath);
- _dl_errno = DL_NOT_FOUND;
- return (object);
- }
- *lname = '\0';
- lname++;
- if (*lname == '\0') {
- _dl_free(lpath);
- _dl_errno = DL_NOT_FOUND;
- return (object);
- }
-
- _dl_build_sod(lname, &sod);
- req_sod = sod;
+ (*_dl_strrchr(lpath, '/')) = '\0';
paths[0] = lpath;
paths[1] = NULL;
@@ -352,15 +357,6 @@ fullpathagain:
fullpathdone:
_dl_free(lpath);
goto done;
- }
-
- _dl_build_sod(libname, &sod);
- req_sod = sod;
-
- object = _dl_find_loaded_shlib(libname, req_sod, flags);
- if (object) {
- _dl_free((char *)sod.sod_name);
- return (object);
}
again: