handle library paths better (ignore empty path components, etc.)
authorRich Felker <dalias@aerifal.cx>
Sat, 25 Jun 2011 21:49:16 +0000 (17:49 -0400)
committerRich Felker <dalias@aerifal.cx>
Sat, 25 Jun 2011 21:49:16 +0000 (17:49 -0400)
src/ldso/dynlink.c

index 56ba89eb57b4f20f90ed2753de1d2df84b2ea80f..472e389d6ccc89bd16a5c774abb03f4ae5e0ca57 100644 (file)
@@ -208,15 +208,17 @@ static void *map_library(int fd, size_t *lenp, unsigned char **basep, size_t *dy
 static int path_open(const char *name, const char *search)
 {
        char buf[2*NAME_MAX+2];
-       const char *s, *z;
+       const char *s=search, *z;
        int l, fd;
-       for (s=search; *s; s+=l+!!z) {
+       for (;;) {
+               while (*s==':') s++;
+               if (!*s) return -1;
                z = strchr(s, ':');
                l = z ? z-s : strlen(s);
                snprintf(buf, sizeof buf, "%.*s/%s", l, s, name);
                if ((fd = open(buf, O_RDONLY))>=0) return fd;
+               s += l;
        }
-       return -1;
 }
 
 static struct dso *load_library(const char *name)