From 143e2b96c94c3fd5a2c618db0bad094ce659e743 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Wed, 2 Sep 1998 12:58:42 +0000 Subject: [PATCH] Update. 1998-09-02 Ulrich Drepper * elf/dl-load.c (fillin_rpath): Handle "/" as RPATH correctly. (_dl_map_object_from_fd): Make NAME argument const. Remove last parameter in _dl_new_object call. (print_search_path): Correct construction of composed path name. (_dl_map_object): Prevent looking at RPATH of the main map twice. Remove last parameter in _dl_new_object call. * elf/dl-object.c: Remove last parameter. Determine whether create origin entry based on empty realname. Handle file in root directory correctly. * elf/ldsodefs.h: Adjust prototype for _dl_new_object. * elf/rtld.c (dl_main): Add comment describing reason for memory leak. Remove last parameter in _dl_new_object call. * sysdeps/generic/dl-origin.h: Handle file in root directory correctly. * sysdeps/unix/sysv/linux/dl-origin.h: Likewise. --- ChangeLog | 17 +++++++++++++++++ elf/dl-load.c | 20 +++++++++++--------- elf/dl-object.c | 17 ++++++++++++----- elf/ldsodefs.h | 6 ++---- elf/rtld.c | 6 +++++- sysdeps/generic/dl-origin.h | 4 ++-- sysdeps/unix/sysv/linux/dl-origin.h | 6 ++++-- 7 files changed, 53 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 517f272..929c41a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +1998-09-02 Ulrich Drepper + + * elf/dl-load.c (fillin_rpath): Handle "/" as RPATH correctly. + (_dl_map_object_from_fd): Make NAME argument const. + Remove last parameter in _dl_new_object call. + (print_search_path): Correct construction of composed path name. + (_dl_map_object): Prevent looking at RPATH of the main map twice. + Remove last parameter in _dl_new_object call. + * elf/dl-object.c: Remove last parameter. Determine whether create + origin entry based on empty realname. Handle file in root directory + correctly. + * elf/ldsodefs.h: Adjust prototype for _dl_new_object. + * elf/rtld.c (dl_main): Add comment describing reason for memory leak. + Remove last parameter in _dl_new_object call. + * sysdeps/generic/dl-origin.h: Handle file in root directory correctly. + * sysdeps/unix/sysv/linux/dl-origin.h: Likewise. + 1998-09-01 Ulrich Drepper * elf/dl-close.c (_dl_close): Add more comments and correct some. diff --git a/elf/dl-load.c b/elf/dl-load.c index cb718eb..c9a39c0 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 97edd81..db6e81c 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 b36fcd8..51fecc6 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 b25fb20..66e5d6c 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; diff --git a/sysdeps/generic/dl-origin.h b/sysdeps/generic/dl-origin.h index 6d5a8da..495df60 100644 --- a/sysdeps/generic/dl-origin.h +++ b/sysdeps/generic/dl-origin.h @@ -26,7 +26,7 @@ static inline const char * get_origin (void) { char *result = (char *) -1; - /* We use te environment variable LD_ORIGIN_PATH. If it is set make + /* We use the environment variable LD_ORIGIN_PATH. If it is set make a copy and strip out trailing slashes. */ if (_dl_origin_path != NULL) { @@ -37,7 +37,7 @@ get_origin (void) else { char *cp = __mempcpy (result, _dl_origin_path, len); - while (cp > result && cp[-1] == '/') + while (cp > result + 1 && cp[-1] == '/') --cp; *cp = '\0'; } diff --git a/sysdeps/unix/sysv/linux/dl-origin.h b/sysdeps/unix/sysv/linux/dl-origin.h index f5a9237..5654b42 100644 --- a/sysdeps/unix/sysv/linux/dl-origin.h +++ b/sysdeps/unix/sysv/linux/dl-origin.h @@ -37,13 +37,15 @@ get_origin (void) result = (char *) malloc (last_slash - linkval + 1); if (result == NULL) result = (char *) -1; + else if (last_slash == linkval) + memcpy (result, "/", 2); else *((char *) __mempcpy (result, linkval, last_slash - linkval)) = '\0'; } else { result = (char *) -1; - /* We use te environment variable LD_ORIGIN_PATH. If it is set make + /* We use the environment variable LD_ORIGIN_PATH. If it is set make a copy and strip out trailing slashes. */ if (_dl_origin_path != NULL) { @@ -54,7 +56,7 @@ get_origin (void) else { char *cp = __mempcpy (result, _dl_origin_path, len); - while (cp > result && cp[-1] == '/') + while (cp > result + 1 && cp[-1] == '/') --cp; *cp = '\0'; } -- 2.7.4