Update.
authorUlrich Drepper <drepper@redhat.com>
Sat, 2 Feb 2002 20:17:54 +0000 (20:17 +0000)
committerUlrich Drepper <drepper@redhat.com>
Sat, 2 Feb 2002 20:17:54 +0000 (20:17 +0000)
* elf/dl-object.c (_dl_new_object): Avoid using strrchr.  We have
more information.
* elf/rtld.c (dl_main): Avoid strrchr.
* sysdeps/unix/sysv/linux/dl-origin.c (_dl_get_origin): Use the
result of readlink.  Search from the back for '/'.

ChangeLog
elf/dl-object.c
elf/rtld.c
sysdeps/unix/sysv/linux/dl-origin.c

index 09e1265..a058dbc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2002-02-02  Ulrich Drepper  <drepper@redhat.com>
 
+       * elf/dl-object.c (_dl_new_object): Avoid using strrchr.  We have
+       more information.
+       * elf/rtld.c (dl_main): Avoid strrchr.
+       * sysdeps/unix/sysv/linux/dl-origin.c (_dl_get_origin): Use the
+       result of readlink.  Search from the back for '/'.
+
        * elf/dl-profile.c (_dl_start_profile): Help the compiler to avoid
        strncpy if possible.
 
index 0488e32..398628a 100644 (file)
@@ -150,15 +150,18 @@ _dl_new_object (char *realname, const char *libname, int type,
        }
 
       /* Add the real file name.  */
-      memcpy (cp, realname, realname_len);
+      cp = __mempcpy (cp, realname, realname_len);
 
-      /* Now remove the filename and the slash.  Leave the slash if it
+      /* Now remove the filename and the slash.  Leave the slash if
         the name is something like "/foo".  */
-      cp = strrchr (origin, '/');
+      do
+       --cp;
+      while (*cp != '/');
+
       if (cp == origin)
-       origin[1] = '\0';
-      else
-       *cp = '\0';
+       /* Keep the only slash which is the first character.  */
+       ++cp;
+      *cp = '\0';
 
     out:
       new->l_origin = origin;
index 1efe38b..b835bd5 100644 (file)
@@ -589,10 +589,17 @@ of this helper program; chances are you did not intend to run this program.\n\
           be our SONAME, and add it to our name list.  */
        if (GL(dl_rtld_map).l_ld == NULL)
          {
-           char *p = strrchr (_dl_rtld_libname.name, '/');
-           if (p)
+           const char *p = NULL;
+           const char *cp = _dl_rtld_libname.name;
+
+           /* Find the filename part of the path.  */
+           while (*cp != '\0')
+             if (*cp++ == '/')
+               p = cp;
+
+           if (p != NULL)
              {
-               _dl_rtld_libname2.name = p+1;
+               _dl_rtld_libname2.name = p;
                /* _dl_rtld_libname2.next = NULL;  Already zero.  */
                _dl_rtld_libname.next = &_dl_rtld_libname2;
              }
index 90add58..b054ae2 100644 (file)
@@ -18,6 +18,7 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
+#include <assert.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -35,19 +36,22 @@ _dl_get_origin (void)
 {
   char linkval[PATH_MAX];
   char *result;
+  int len;
 
-  if (__readlink ("/proc/self/exe", linkval, PATH_MAX) != -1
+  if ((len = __readlink ("/proc/self/exe", linkval, PATH_MAX)) > 0
       && linkval[0] != '[')
     {
       /* We can use this value.  */
-      char *last_slash = strrchr (linkval, '/');
-      result = (char *) malloc (last_slash - linkval + 1);
+      assert (linkval[0] == '/');
+      while (len > 1 && linkval[len - 1] != '/')
+       --len;
+      result = (char *) malloc (len + 1);
       if (result == NULL)
        result = (char *) -1;
-      else if (last_slash == linkval)
+      else if (len == 1)
        memcpy (result, "/", 2);
       else
-       *((char *) __mempcpy (result, linkval, last_slash - linkval)) = '\0';
+       *((char *) __mempcpy (result, linkval, len - 1)) = '\0';
     }
   else
     {
@@ -57,7 +61,7 @@ _dl_get_origin (void)
       if (GL(dl_origin_path) != NULL)
        {
          size_t len = strlen (GL(dl_origin_path));
-         result = malloc (len + 1);
+         result = (char *) malloc (len + 1);
          if (result == NULL)
            result = (char *) -1;
          else