don't crash if TLS library is loaded into process with no thread pointer
authorRich Felker <dalias@aerifal.cx>
Sat, 6 Oct 2012 20:56:35 +0000 (16:56 -0400)
committerRich Felker <dalias@aerifal.cx>
Sat, 6 Oct 2012 20:56:35 +0000 (16:56 -0400)
src/ldso/dynlink.c

index db7770b..e944c8e 100644 (file)
@@ -533,6 +533,11 @@ static struct dso *load_library(const char *name)
        /* Add a shortname only if name arg was not an explicit pathname. */
        if (pathname != name) p->shortname = strrchr(p->name, '/')+1;
        if (p->tls_image) {
        /* Add a shortname only if name arg was not an explicit pathname. */
        if (pathname != name) p->shortname = strrchr(p->name, '/')+1;
        if (p->tls_image) {
+               if (!__pthread_self_init()) {
+                       free(p);
+                       munmap(map, map_len);
+                       return 0;
+               }
                p->tls_id = ++tls_cnt;
                tls_align = MAXP2(tls_align, p->tls_align);
                tls_offset += p->tls_size + p->tls_align - 1;
                p->tls_id = ++tls_cnt;
                tls_align = MAXP2(tls_align, p->tls_align);
                tls_offset += p->tls_size + p->tls_align - 1;