From 45af1203bdb5d1ccccc27526ce38c36f49196ccc Mon Sep 17 00:00:00 2001 From: larinsv <97248465+larinsv@users.noreply.github.com> Date: Wed, 18 May 2022 13:16:00 +0300 Subject: [PATCH] Fixed race condition that occurs when initializing the executable_allocator_is_working variable in the pcre2_jit_compile function (#91) Conflict:adapt context Reference:https://github.com/PhilipHazel/pcre2/commit/45af1203bdb5d1ccccc27526ce38c36f49196ccc --- src/pcre2_jit_compile.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/pcre2_jit_compile.c b/src/pcre2_jit_compile.c index 64c18f7..6155ed7 100644 --- a/src/pcre2_jit_compile.c +++ b/src/pcre2_jit_compile.c @@ -14184,7 +14184,7 @@ actions are needed: #ifdef SUPPORT_JIT executable_functions *functions = (executable_functions *)re->executable_jit; -static int executable_allocator_is_working = 0; +static int executable_allocator_is_working = -1; #endif if ((options & PCRE2_JIT_INVALID_UTF) != 0) @@ -14211,23 +14211,22 @@ return PCRE2_ERROR_JIT_BADOPTION; if ((re->flags & PCRE2_NOJIT) != 0) return 0; -if (executable_allocator_is_working == 0) +if (executable_allocator_is_working == -1) { /* Checks whether the executable allocator is working. This check might run multiple times in multi-threaded environments, but the result should not be affected by it. */ void *ptr = SLJIT_MALLOC_EXEC(32); - executable_allocator_is_working = -1; - if (ptr != NULL) { SLJIT_FREE_EXEC(((sljit_u8*)(ptr)) + SLJIT_EXEC_OFFSET(ptr)); executable_allocator_is_working = 1; } + else executable_allocator_is_working = 0; } -if (executable_allocator_is_working < 0) +if (!executable_allocator_is_working) return PCRE2_ERROR_NOMEMORY; if ((re->overall_options & PCRE2_MATCH_INVALID_UTF) != 0) -- 2.27.0