Skip to content

Commit 5667be1

Browse files
authored
0-initialize thread-specific data upon thread creation. (#508)
If thread-specific data is not set to 0 upon thread creation, `__pthread_tsd_run_dtors` will end up running destructors passing uninitialized memory as memory addresses, which can lead to memory corruption. This issue can be triggered when malloc() returns a memory address that was freed before, as in that case memory is not zeroed out.
1 parent 67080fa commit 5667be1

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

libc-top-half/musl/src/thread/pthread_create.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,9 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
458458
if (!map) goto fail;
459459
#endif
460460
tsd = map + size - __pthread_tsd_size;
461+
#ifndef __wasilibc_unmodified_upstream
462+
memset(tsd, 0, __pthread_tsd_size);
463+
#endif
461464
if (!stack) {
462465
#ifdef __wasilibc_unmodified_upstream
463466
stack = tsd - libc.tls_size;

0 commit comments

Comments
 (0)