about summary refs log tree commit diff
path: root/sysdeps
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/generic/dl-origin.h4
-rw-r--r--sysdeps/unix/sysv/linux/dl-origin.h6
2 files changed, 6 insertions, 4 deletions
diff --git a/sysdeps/generic/dl-origin.h b/sysdeps/generic/dl-origin.h
index 6d5a8da52e..495df60296 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 f5a92379db..5654b42a2f 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';
 	    }