summaryrefslogtreecommitdiff
path: root/elf
diff options
context:
space:
mode:
Diffstat (limited to 'elf')
-rw-r--r--elf/dl-load.c20
-rw-r--r--elf/dl-object.c17
-rw-r--r--elf/ldsodefs.h6
-rw-r--r--elf/rtld.c6
4 files changed, 30 insertions, 19 deletions
diff --git a/elf/dl-load.c b/elf/dl-load.c
index cb718eb2c6..c9a39c01a2 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -297,7 +297,7 @@ fillin_rpath (char *rpath, struct r_search_path_elem **result, const char *sep,
cp = strcpy (curwd, ".");
}
- /* Remove trailing slashes. */
+ /* Remove trailing slashes (except for "/"). */
while (len > 1 && cp[len - 1] == '/')
--len;
@@ -321,8 +321,8 @@ fillin_rpath (char *rpath, struct r_search_path_elem **result, const char *sep,
continue;
}
- /* Now add one. */
- if (len > 0)
+ /* Now add one if there is none so far. */
+ if (len > 0 && cp[len - 1] != '/')
cp[len++] = '/';
/* See if this directory is already known. */
@@ -609,7 +609,7 @@ _dl_init_paths (const char *llp)
static
#endif
struct link_map *
-_dl_map_object_from_fd (char *name, int fd, char *realname,
+_dl_map_object_from_fd (const char *name, int fd, char *realname,
struct link_map *loader, int l_type)
{
struct link_map *l = NULL;
@@ -727,7 +727,7 @@ _dl_map_object_from_fd (char *name, int fd, char *realname,
#endif
/* Enter the new object in the list of loaded objects. */
- l = _dl_new_object (realname, name, l_type, loader != NULL);
+ l = _dl_new_object (realname, name, l_type);
if (! l)
lose (ENOMEM, "cannot create shared object descriptor");
l->l_opencount = 1;
@@ -995,7 +995,10 @@ print_search_path (struct r_search_path_elem **list,
if ((*list)->status[cnt] != nonexisting)
{
char *cp = __mempcpy (endp, capstr[cnt].str, capstr[cnt].len);
- cp[-1] = '\0';
+ if (cp == buf || (cp == buf + 1 && buf[0] == '/'))
+ cp[0] = '\0';
+ else
+ cp[-1] = '\0';
_dl_debug_message (0, first ? "" : ":", buf, NULL);
first = 0;
}
@@ -1211,7 +1214,7 @@ _dl_map_object (struct link_map *loader, const char *name, int preloaded,
/* If dynamically linked, try the DT_RPATH of the executable itself
and the LD_LIBRARY_PATH environment variable. */
l = _dl_loaded;
- if (fd == -1 && l && l->l_type != lt_loaded
+ if (fd == -1 && l && l->l_type != lt_loaded && l != loader
&& l->l_rpath_dirs != (struct r_search_path_elem **) -1l)
fd = open_path (name, namelen, preloaded, l->l_rpath_dirs, &realname);
@@ -1277,8 +1280,7 @@ _dl_map_object (struct link_map *loader, const char *name, int preloaded,
/* Enter the new object in the list of loaded objects. */
if ((name_copy = local_strdup (name)) == NULL
- || (l = _dl_new_object (name_copy, name, type,
- loader != NULL)) == NULL)
+ || (l = _dl_new_object (name_copy, name, type)) == NULL)
_dl_signal_error (ENOMEM, name,
"cannot create shared object descriptor");
/* We use an opencount of 0 as a sign for the faked entry. */
diff --git a/elf/dl-object.c b/elf/dl-object.c
index 97edd8189c..db6e81c11e 100644
--- a/elf/dl-object.c
+++ b/elf/dl-object.c
@@ -33,7 +33,7 @@ struct link_map *_dl_default_scope[5];
struct link_map *
internal_function
-_dl_new_object (char *realname, const char *libname, int type, int find_origin)
+_dl_new_object (char *realname, const char *libname, int type)
{
size_t libname_len = strlen (libname) + 1;
struct link_map *new = calloc (sizeof *new, 1);
@@ -63,7 +63,7 @@ _dl_new_object (char *realname, const char *libname, int type, int find_origin)
}
/* Don't try to find the origin for the main map. */
- if (! find_origin)
+ if (realname[0] == '\0')
new->l_origin = NULL;
else
{
@@ -117,9 +117,16 @@ _dl_new_object (char *realname, const char *libname, int type, int find_origin)
}
if (origin != (char *) -1)
- /* Now remove the filename and the slash. Do this even if the
- string is something like "/foo" which leaves an empty string. */
- *strrchr (origin, '/') = '\0';
+ {
+ /* Now remove the filename and the slash. Do this even if the
+ string is something like "/foo" which leaves an empty string. */
+ char *last = strrchr (origin, '/');
+
+ if (last == origin)
+ origin[1] = '\0';
+ else
+ *last = '\0';
+ }
new->l_origin = origin;
}
diff --git a/elf/ldsodefs.h b/elf/ldsodefs.h
index b36fcd8725..51fecc6eb7 100644
--- a/elf/ldsodefs.h
+++ b/elf/ldsodefs.h
@@ -356,11 +356,9 @@ extern struct link_map **_dl_object_relocation_scope (struct link_map *map)
/* Allocate a `struct link_map' for a new object being loaded,
- and enter it into the _dl_loaded list. If find origin is nonzero
- determine the origin of the file. */
+ and enter it into the _dl_loaded list. */
extern struct link_map *_dl_new_object (char *realname, const char *libname,
- int type, int find_origin)
- internal_function;
+ int type) internal_function;
/* Relocate the given object (if it hasn't already been).
SCOPE is passed to _dl_lookup_symbol in symbol lookups.
diff --git a/elf/rtld.c b/elf/rtld.c
index b25fb20fd3..66e5d6c59d 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -417,6 +417,10 @@ of this helper program; chances are you did not intend to run this program.\n\
phdr = main_map->l_phdr;
phent = main_map->l_phnum;
+ /* We overwrite here a pointer to a malloc()ed string. But since
+ the malloc() implementation used at this point is the dummy
+ implementations which has no real free() function it does not
+ makes sense to free the old string first. */
main_map->l_name = (char *) "";
*user_entry = main_map->l_entry;
}
@@ -424,7 +428,7 @@ of this helper program; chances are you did not intend to run this program.\n\
{
/* Create a link_map for the executable itself.
This will be what dlopen on "" returns. */
- main_map = _dl_new_object ((char *) "", "", lt_executable, 0);
+ main_map = _dl_new_object ((char *) "", "", lt_executable);
if (main_map == NULL)
_dl_sysdep_fatal ("cannot allocate memory for link map\n", NULL);
main_map->l_phdr = phdr;