Skip to content

Serialize public API with a global lock (GHSA-q2v4-fh98-357r)#248

Closed
manugarg wants to merge 1 commit into
mainfrom
harden/global-lock
Closed

Serialize public API with a global lock (GHSA-q2v4-fh98-357r)#248
manugarg wants to merge 1 commit into
mainfrom
harden/global-lock

Conversation

@manugarg

Copy link
Copy Markdown
Owner

Summary

  • Guard every public pacparser_* entry point with a single recursive global lock (pthread mutex on POSIX, CRITICAL_SECTION on Windows) so a thread in find_proxy() can't be racing a cleanup() that frees the QuickJS engine out from under it.
  • The lock only serializes calls; pacparser is still a single global interpreter and does not run PAC scripts concurrently. Pairs with the docs PR (Document that the pacparser API is not thread-safe #247).

Test plan

  • NO_INTERNET=1 make -C src — builds clean, full test suite passes.
  • Reporter's PoC against this branch: 5/5 clean exits; against main: 5/5 JS_FreeRuntime assertion aborts.
  • Python module build not run locally (no setuptools in this env); setup.py change is the -pthread link arg only.

Notes

  • This does not change the lifetime caveat of find_proxy()'s returned pointer (valid until the next call/cleanup) — the lock prevents the concurrent use-after-free during execution, not a caller holding a stale pointer.

🤖 Generated with Claude Code

pacparser keeps its QuickJS runtime/context in process-global state with
no synchronization, so a thread in pacparser_find_proxy() racing a
pacparser_cleanup() on another thread can free the engine mid-use
(assert abort, or heap-use-after-free in -DNDEBUG builds).

Guard every public entry point with a single recursive lock (pthread
mutex on POSIX, CRITICAL_SECTION on Windows). The lock is recursive so
the composite entry points keep working; it only serializes calls and
does not make pacparser run PAC scripts concurrently.

Link against -pthread in the Makefile and the Python extension.

Fixes GHSA-q2v4-fh98-357r.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@manugarg

manugarg commented Jul 1, 2026

Copy link
Copy Markdown
Owner Author

I don't think this is worth doing.

@manugarg manugarg closed this Jul 1, 2026
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.

1 participant