Skip to content

Make make_absolute thread-local in chdir.c#781

Open
CPunisher wants to merge 2 commits intoWebAssembly:mainfrom
CPunisher:04-03-fix/make_absolute
Open

Make make_absolute thread-local in chdir.c#781
CPunisher wants to merge 2 commits intoWebAssembly:mainfrom
CPunisher:04-03-fix/make_absolute

Conversation

@CPunisher
Copy link
Copy Markdown

make_absolute previously used a process-wide static buffer to assemble absolute paths for relative path resolution. In _REENTRANT builds, concurrent calls could overwrite or reallocate that shared buffer while another thread was still using it, leading to races and potentially invalid pointers.

Related #474

@alexcrichton
Copy link
Copy Markdown
Collaborator

Thanks for the PR! I think though this might be something that's more appropriate to use synchronization for rather than thread-local storage. These are malloc'd buffers which means that if it were thread-local then a thread exiting would leak the buffer information. As a static that doesn't matter too much as the leaked memory is bounded, but adding threads into the mix could make it much worse. Could this use a mutex intead?

@CPunisher
Copy link
Copy Markdown
Author

CPunisher commented Apr 8, 2026

I've updated the code to use synchronization instead of thread-local storage.

I ended up protecting the whole __wasilibc_find_relpath_alloc with a mutex, because the lifetime of make_absolute_buf extends until strcpy(*relative_buf, rel).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants