Copilot commented on code in PR #13661:
URL: https://github.com/apache/trafficserver/pull/13661#discussion_r3983985498
##########
src/tsutil/Regex.cc:
##########
@@ -79,6 +80,46 @@ my_free(void *ptr, void * /*caller*/)
free(ptr);
}
+//----------------------------------------------------------------------------
+// One match context is shared by every thread that matches through it, and
PCRE2
+// requires a distinct JIT stack per thread, so the stack comes from a callback
+// invoked at match time rather than a pointer baked in when the context is
built.
+//
+// The per thread stack is held in a pthread key rather than a thread_local. A
+// thread_local with a destructor registers it through __cxa_thread_atexit,
which
+// takes the dynamic loader lock; doing that from a match would invert lock
order
+// against a dlopen caller running a plugin's static initialization. See the
same
+// hazard described at Diags::tag_activated. A pthread key registers its
destructor
+// once, at key creation, and never from the matching path.
+pthread_key_t jit_stack_key;
+pthread_once_t jit_stack_key_once = PTHREAD_ONCE_INIT;
+
+void
+destroy_jit_stack(void *stack)
+{
+ if (stack != nullptr) {
+ pcre2_jit_stack_free(static_cast<pcre2_jit_stack *>(stack));
+ }
+}
+
+void
+make_jit_stack_key()
+{
+ pthread_key_create(&jit_stack_key, destroy_jit_stack);
Review Comment:
`pthread_key_create` can fail (for example with `EAGAIN` or `ENOMEM`), but
this return value is ignored. `pthread_once` will still mark the initializer
complete while `jit_stack_key` remains invalid/default-initialized, so the
following `pthread_getspecific`/`pthread_setspecific` calls can use an invalid
or unrelated key and return an unrelated pointer as a JIT stack. Check the
creation result and make the callback handle key-initialization failure before
using the key.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]