Commit de676c22 authored by Geoff Simmons's avatar Geoff Simmons

Lock initialization of PRIV_CALL-scoped data.

parent 4d9878cb
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
*/ */
#include <locale.h> #include <locale.h>
#include <pthread.h>
#include "vmod_pcre2.h" #include "vmod_pcre2.h"
...@@ -36,6 +37,9 @@ ...@@ -36,6 +37,9 @@
AZ(pcre2_set_##param((ctx), (type)(param))); \ AZ(pcre2_set_##param((ctx), (type)(param))); \
} while(0) } while(0)
/* Locks initialization of PRIV_CALL-scoped data. */
static pthread_mutex_t call_lock = PTHREAD_MUTEX_INITIALIZER;
void void
errmsg(VRT_CTX, const char *fmt, ...) errmsg(VRT_CTX, const char *fmt, ...)
{ {
...@@ -245,20 +249,28 @@ get_match_opts(VRT_CTX, struct vmod_priv *priv, MATCH_CTX_OPTS, MATCH_FLAGS, ...@@ -245,20 +249,28 @@ get_match_opts(VRT_CTX, struct vmod_priv *priv, MATCH_CTX_OPTS, MATCH_FLAGS,
struct match_call *match_opts; struct match_call *match_opts;
pcre2_match_context *mctx; pcre2_match_context *mctx;
AZ(pthread_mutex_lock(&call_lock));
if (priv->priv != NULL) {
/* Someone beat us to it. */
AZ(pthread_mutex_unlock(&call_lock));
CAST_OBJ(match_opts, priv->priv, VMOD_PCRE2_MATCH_CALL_MAGIC);
return match_opts;
}
if (!check_uint32_range(ctx, match_limit, "match_limit", context, if (!check_uint32_range(ctx, match_limit, "match_limit", context,
caller)) caller))
return NULL; goto fail;
if (!check_uint32_range(ctx, offset_limit, "offset_limit", context, if (!check_uint32_range(ctx, offset_limit, "offset_limit", context,
caller)) caller))
return NULL; goto fail;
if (!check_uint32_range(ctx, recursion_limit, "recursion_limit", if (!check_uint32_range(ctx, recursion_limit, "recursion_limit",
context, caller)) context, caller))
return NULL; goto fail;
if ((mctx = pcre2_match_context_create(NULL)) == NULL) { if ((mctx = pcre2_match_context_create(NULL)) == NULL) {
VERRNOMEM(ctx, "creating match context in %s%s", context, VERRNOMEM(ctx, "creating match context in %s%s", context,
caller); caller);
return NULL; goto fail;
} }
SET_CTX_PARAM(mctx, match_limit, uint32_t); SET_CTX_PARAM(mctx, match_limit, uint32_t);
SET_CTX_PARAM(mctx, offset_limit, uint32_t); SET_CTX_PARAM(mctx, offset_limit, uint32_t);
...@@ -268,7 +280,7 @@ get_match_opts(VRT_CTX, struct vmod_priv *priv, MATCH_CTX_OPTS, MATCH_FLAGS, ...@@ -268,7 +280,7 @@ get_match_opts(VRT_CTX, struct vmod_priv *priv, MATCH_CTX_OPTS, MATCH_FLAGS,
if (match_opts == NULL) { if (match_opts == NULL) {
VERRNOMEM(ctx, "allocating call-scoped match options in %s%s", VERRNOMEM(ctx, "allocating call-scoped match options in %s%s",
context, caller); context, caller);
return NULL; goto fail;
} }
match_opts->mctx = mctx; match_opts->mctx = mctx;
set_match_flags(&match_opts->match_options, MATCH_SUB_FLAGS_PARAMS); set_match_flags(&match_opts->match_options, MATCH_SUB_FLAGS_PARAMS);
...@@ -277,5 +289,10 @@ get_match_opts(VRT_CTX, struct vmod_priv *priv, MATCH_CTX_OPTS, MATCH_FLAGS, ...@@ -277,5 +289,10 @@ get_match_opts(VRT_CTX, struct vmod_priv *priv, MATCH_CTX_OPTS, MATCH_FLAGS,
priv->free = match_call_free; priv->free = match_call_free;
priv->len = sizeof(*match_opts); priv->len = sizeof(*match_opts);
AZ(pthread_mutex_unlock(&call_lock));
return match_opts; return match_opts;
fail:
AZ(pthread_mutex_unlock(&call_lock));
return NULL;
} }
...@@ -546,7 +546,6 @@ vmod_match(VRT_CTX, struct vmod_priv *call, struct vmod_priv *task, ...@@ -546,7 +546,6 @@ vmod_match(VRT_CTX, struct vmod_priv *call, struct vmod_priv *task,
} }
/* Compile and match options saved in PRIV_CALL scope */ /* Compile and match options saved in PRIV_CALL scope */
/* XXX need a lock */
if (call->priv != NULL) if (call->priv != NULL)
CAST_OBJ(match_call, call->priv, VMOD_PCRE2_MATCH_CALL_MAGIC); CAST_OBJ(match_call, call->priv, VMOD_PCRE2_MATCH_CALL_MAGIC);
else if ((match_call = get_match_opts(ctx, call, MATCH_CTX_PARAMS, else if ((match_call = get_match_opts(ctx, call, MATCH_CTX_PARAMS,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment