fix dlerror when using dlopen with a static libc
[musl] / src / ldso / dynlink.c
index 55124ff..aa1b99a 100644 (file)
@@ -663,6 +663,11 @@ static struct dso *load_library(const char *name, struct dso *needed_by)
        int n_th = 0;
        int is_self = 0;
 
+       if (!*name) {
+               errno = EINVAL;
+               return 0;
+       }
+
        /* Catch and block attempts to reload the implementation itself */
        if (name[0]=='l' && name[1]=='i' && name[2]=='b') {
                static const char *rp, reserved[] =
@@ -862,8 +867,8 @@ static void load_preload(char *s)
        int tmp;
        char *z;
        for (z=s; *z; s=z) {
-               for (   ; *s && isspace(*s); s++);
-               for (z=s; *z && !isspace(*z); z++);
+               for (   ; *s && (isspace(*s) || *s==':'); s++);
+               for (z=s; *z && !isspace(*z) && *z!=':'; z++);
                tmp = *z;
                *z = 0;
                load_library(s, 0);
@@ -1598,6 +1603,8 @@ static int invalid_dso_handle(void *h)
 }
 void *dlopen(const char *file, int mode)
 {
+       strcpy(errbuf, "Dynamic loading not supported");
+       errflag = 1;
        return 0;
 }
 void *__dlsym(void *restrict p, const char *restrict s, void *restrict ra)