Browse Source

[core] allocate one fewer cond_match_t, if needed

allocate one fewer cond_match_t in r->cond_match_data, if any are needed
master
Glenn Strauss 2 months ago
parent
commit
670b3a395f
  1. 6
      src/configfile-glue.c
  2. 3
      src/configfile.c
  3. 2
      src/h2.c
  4. 2
      src/mod_redirect.c
  5. 2
      src/mod_rewrite.c

6
src/configfile-glue.c

@ -651,8 +651,9 @@ static int config_pcre_match(request_st * const r, const data_config * const dc,
return pcre2_match(dc->code, (PCRE2_SPTR)BUF_PTR_LEN(b),
0, 0, dc->match_data, NULL);
const int capture_offset = dc->capture_idx - 1;
cond_match_t * const cond_match =
r->cond_match[dc->capture_idx] = r->cond_match_data + dc->capture_idx;
r->cond_match[capture_offset] = r->cond_match_data + capture_offset;
pcre2_match_data *match_data = cond_match->match_data;
if (__builtin_expect( (NULL == match_data), 0)) {
/*(allocate on demand)*/
@ -689,8 +690,9 @@ static int config_pcre_match(request_st * const r, const data_config * const dc,
#ifndef elementsof
#define elementsof(x) (sizeof(x) / sizeof(x[0]))
#endif
const int capture_offset = dc->capture_idx - 1;
cond_match_t * const cond_match =
r->cond_match[dc->capture_idx] = r->cond_match_data + dc->capture_idx;
r->cond_match[capture_offset] = r->cond_match_data + capture_offset;
cond_match->comp_value = b; /*holds pointer to b (!) for pattern subst*/
cond_match->captures =
pcre_exec(dc->regex, dc->regex_study, BUF_PTR_LEN(b), 0, 0,

3
src/configfile.c

@ -1233,9 +1233,6 @@ int config_finalize(server *srv, const buffer *default_server_tag) {
return 0;
}
/* adjust cond_match_data list size if regex config conditions present */
if (srv->config_captures) ++srv->config_captures;
#ifdef HAVE_PCRE2_H
for (uint32_t i = 1; i < srv->config_context->used; ++i) {
data_config * const dc =

2
src/h2.c

@ -2571,7 +2571,7 @@ h2_init_stream (request_st * const h2r, connection * const con)
r->conditional_is_valid = h2r->conditional_is_valid;
memcpy(r->cond_cache, h2r->cond_cache, used * sizeof(cond_cache_t));
#ifdef HAVE_PCRE
if (srv->config_captures > 1)
if (srv->config_captures)
memcpy(r->cond_match, h2r->cond_match,
srv->config_captures * sizeof(cond_match_t));
#endif

2
src/mod_redirect.c

@ -169,7 +169,7 @@ URIHANDLER_FUNC(mod_redirect_uri_handler) {
ctx.cache = NULL;
if (p->conf.redirect->x0) { /*(p->conf.redirect->x0 is capture_idx)*/
ctx.cache = r->cond_match[p->conf.redirect->x0];
ctx.cache = r->cond_match[p->conf.redirect->x0 - 1];
}
ctx.burl = &burl;
burl.scheme = &r->uri.scheme;

2
src/mod_rewrite.c

@ -291,7 +291,7 @@ static handler_t process_rewrite_rules(request_st * const r, plugin_data *p, con
ctx.cache = NULL;
if (kvb->x0) { /*(kvb->x0 is capture_idx)*/
ctx.cache = r->cond_match[kvb->x0];
ctx.cache = r->cond_match[kvb->x0 - 1];
}
ctx.burl = &burl;
burl.scheme = &r->uri.scheme;

Loading…
Cancel
Save