55 Commits

Author SHA1 Message Date
97a1873332 regex: Add AP_REG_NOTEMPTY_ATSTART maching option.
* include/ap_mmn.h:
  Bump MMN minor.

* include/ap_regex.h:
  Define AP_REG_NOTEMPTY_ATSTART bit.

* server/util_pcre.c(ap_regexec_ex):
  Map AP_REG_NOTEMPTY_ATSTART to native PCRE_NOTEMPTY_ATSTART.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1915268 13f79535-47bb-0310-9956-ffa450edef68
2024-01-16 16:56:58 +00:00
e52a206008 regex: Add ap_regexec_ex() which can take a starting offset to match from.
* include/ap_mmn.h:
  Bump MMN minor.

* include/ap_regex.h:
  Declare ap_regexec_ex().

* server/util_pcre.c(ap_regexec, ap_regexec_len, ap_regexec_ex):
  Reuse existing ap_regexec_len() code to implement ap_regexec_ex() where the
  offset is given instead of zero, then implement ap_regexec{,len}() in terms
  of ap_regexec_ex().



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1915267 13f79535-47bb-0310-9956-ffa450edef68
2024-01-16 16:51:03 +00:00
dd434a2f91 util_cpre: Follow up to r1902731: Simplify thread pool allocation.
We don't need to over-allocate pool/heap buffers and handle the (used) size,
let apr_palloc() do this exact work for us.

That way we only need an AP_THREAD_LOCAL pool with no buffer tracking, simpler.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1902858 13f79535-47bb-0310-9956-ffa450edef68
2022-07-19 16:18:03 +00:00
c89c1bf394 util: Follow up to r1902728 and r1902731: static/AP_THREAD_LOCAL order matters.
gcc seems to want "static __thread"  instead of "__thread static"..



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1902733 13f79535-47bb-0310-9956-ffa450edef68
2022-07-15 11:49:30 +00:00
97afea48fd util_pcre: Restore nmatch < ncaps behaviour with PCRE1 (only).
When the requested nmatch is below the number of captures for the regex (i.e.
nmatch is zero if the user does not care about the captures), with PCRE1 we can
pass a smaller ovector to pcre_exec() (or even NULL) which allows for somes
optimizations (less or even no recursion) internally in pcre.

This might avoid crashes due to stack usage/exhaustion with pathological
patterns (see BZ 66119).



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1902732 13f79535-47bb-0310-9956-ffa450edef68
2022-07-15 10:46:37 +00:00
f589ecaa68 util_pcre: Add a thread local subpool cache for when stack does not suffice.
When AP_HAS_THREAD_LOCAL is available, use a thread-local match_thread_state to
save per-thread data in a subpool of the thread's pool.

If private_malloc() gets out of the stack buffer and the current thread has a
pool (i.e. ap_thread_current() != NULL), it will apr_palloc()ate and return
memory from the subpool.

When the match is complete and the match_data are freed, the thread subpool is
cleared thus giving back the memory to the allocator, which itself will give
back the memory or recycle it depending on its max_free setting.

* util_pcre.c:
  Restore POSIX_MALLOC_THRESHOLDsince this is part of the user API.

* util_pcre.c(match_data_pt):
  Type not used (explicitely) anymore, axe.
  
* util_pcre.c(struct match_data_state):
  Put the stack buffer there to simplify code (the state is allocated on
  stack anyway).
  If APREG_USE_THREAD_LOCAL, add the apr_thread_t* and match_thread_state*
  fields that track the thread local data for the match.

* util_pcre.c(alloc_match_data, free_match):
  Renamed to setup_state() and cleanup_state(), simplified (no stack buffer
  parameters anymore).
  cleanup_state() now clears the thread local subpool if used during the match.
  setup_state() set state->thd to ap_thread_current(), thus NULL if it's not a
  suitable thread for using thread local data.

* util_pcre.c(private_malloc):
  Fix a possible buf_used overflow (size <= avail < APR_ALIGN_DEFAULT(size)).
  Create the thread local subpool (once per thread) and allocate from there
  when stack space is missing and state->thd != NULL, otherwise fall back to
  malloc() still.

* util_pcre.c(private_free):
  Do nothing for thread local subpool memory, will be freed in cleanup_state
  eventually.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1902731 13f79535-47bb-0310-9956-ffa450edef68
2022-07-15 10:36:24 +00:00
7641312e07 Follow-up to r1902572: Remove now unused #include.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1902573 13f79535-47bb-0310-9956-ffa450edef68
2022-07-08 16:24:37 +00:00
b93394ec69 Rewrite ap_regexec() without a thread-local storage context for allocations.
Provide custom malloc() and free() implementations that use a stack buffer
for first N bytes and then fall back to an ordinary malloc/free().

The key properties of this approach are:

1) Allocations with PCRE2 happen the same way as they were happening
with PCRE1 in httpd 2.4.52 and earlier.

2) There are no malloc()/free() calls for typical cases where the
match data can be kept on stack.

3) The patch avoids a malloc() for the match_data structure itself,
because the match data is allocated with the provided custom malloc()
function.

4) Using custom allocation functions should ensure that PCRE is not
going to use malloc() for any auxiliary allocations, if they are
necessary.

5) There is no per-thread state.

References:
1) https://lists.apache.org/thread/l6m7dqjkk0yy3tooyd2so0rb20jmtpwd
2) https://lists.apache.org/thread/5k9y264whn4f1ll35tvl2164dz0wphvy


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1902572 13f79535-47bb-0310-9956-ffa450edef68
2022-07-08 15:07:00 +00:00
7833dc9148 core: Follow up to r1897240: Opt-out for AP_HAS_THREAD_LOCAL and/or pcre's usage.
If the compiler's thread_local is not efficient enough on some platforms, or
not desired, have a way to disable its usage in httpd (at compile time).

Handle -DAP_NO_THREAD_LOCAL and/or -DAPREG_NO_THREAD_LOCAL as build opt-out for
thread_local usage in httpd gobally and/or in ap_regex only (respectively).



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1897689 13f79535-47bb-0310-9956-ffa450edef68
2022-02-02 10:02:26 +00:00
29412ec3ec ap_regex: Follow up to r1897240: Fetch the ovector _after_ the match.
Possibly(?) pcre2_match() can modifiy the given pcre2_match_data and invalidate
the old ovector, be safe and fetch it after.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1897651 13f79535-47bb-0310-9956-ffa450edef68
2022-02-01 10:51:30 +00:00
6044859057 core: Efficient ap_thread_current() when apr_thread_local() is missing.
#define ap_thread_create, ap_thread_current_create and ap_thread_current to
their apr-1.8+ equivalent if available, or implement them using the compiler's
thread_local mechanism if available, or finally provide stubs otherwise.

#define AP_HAS_THREAD_LOCAL to 1 in the two former case or 0 otherwise, while
AP_THREAD_LOCAL is defined to the compiler's keyword iff AP_HAS_THREAD_LOCAL.

Replace all apr_thread_create() calls with ap_thread_create() so that httpd
threads can use ap_thread_current()'s pool data as Thread Local Storage.

Bump MMN minor.

* include/httpd.h():
  Define AP_HAS_THREAD_LOCAL, AP_THREAD_LOCAL (eventually), ap_thread_create(),
  ap_thread_current_create() and ap_thread_current().
  
* server/util.c:
  Implement ap_thread_create(), ap_thread_current_create() and
  ap_thread_current() when APR < 1.8.

* modules/core/mod_watchdog.c, modules/http2/h2_workers.c,
    modules/ssl/mod_ssl_ct.c:
  Use ap_thread_create() instead of apr_thread_create.

* server/main.c:
  Use AP_HAS_THREAD_LOCAL and ap_thread_current_create instead of APR's.

* server/util_pcre.c:
  Use AP_HAS_THREAD_LOCAL and ap_thread_current instead of APR's.

* server/mpm/event/event.c, server/mpm/worker/worker.c,
    server/mpm/prefork/prefork.c:
  Use ap_thread_create() instead of apr_thread_create.
  Create an apr_thread_t/ap_thread_current() for the main chaild thread usable
  at child_init().
  
* server/mpm/winnt/child.c:
  Use ap_thread_create() instead of CreateThread().
  Create an apr_thread_t/ap_thread_current() for the main chaild thread usable



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1897460 13f79535-47bb-0310-9956-ffa450edef68
2022-01-25 17:34:57 +00:00
a6f105f7d4 ap_regex: Follow up to r1897240: #if APR_HAS_THREAD_LOCAL, not #ifdef.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1897459 13f79535-47bb-0310-9956-ffa450edef68
2022-01-25 16:41:48 +00:00
225d471b6e ap_regex: Follow up to r1897240: cleanup PCRE2 match data on exit.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1897386 13f79535-47bb-0310-9956-ffa450edef68
2022-01-23 20:48:29 +00:00
ae3f330762 ap_regex: Follow up to r1897240: cleanups.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1897263 13f79535-47bb-0310-9956-ffa450edef68
2022-01-20 18:20:40 +00:00
d31bcd5995 ap_regex: Follow up to r1897240: no ap_thread_current() yet.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1897261 13f79535-47bb-0310-9956-ffa450edef68
2022-01-20 17:08:02 +00:00
9cda8538a6 ap_regex: Follow up to r1897240: runtime fallback to alloc/free.
Even though APR_HAS_THREAD_LOCAL is compiled in, ap_regexec() might still be
called by non a apr_thread_t thread, let's fall back to alloc/free in this
case too.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1897260 13f79535-47bb-0310-9956-ffa450edef68
2022-01-20 17:01:40 +00:00
f01e29d89d ap_regex: Follow up to r1897240: Fix issues spotted by Rüdiger (thanks!).
#include "apr_thread_proc.h" is enough/needed by util_pcre.c and main.c.
Fix compilation (vector => ovector) for !HAVE_PCRE2 && APR_HAS_THREAD_LOCAL.
Check pcre2_match_data_create() return value for HAVE_PCRE2 && !APR_HAS_THREAD_LOCAL.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1897250 13f79535-47bb-0310-9956-ffa450edef68
2022-01-20 13:15:36 +00:00
38dddb187a ap_regex: Follow up to r1897244: Fix pmatch overflow and returned value at limits.
Don't write to pmatch[nlimit:] when ncaps > nlimit, rc should not exceed nmatch
either as before r1897244.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1897248 13f79535-47bb-0310-9956-ffa450edef68
2022-01-20 12:47:02 +00:00
2a59c92368 ap_regex: PCRE needs buffers sized against the number of captures only.
No more (useless), no less (or PCRE will allocate a new buffer by itself to
satisfy the needs), so we should base our buffer size solely on the number
of captures in the regex (determined at compile time from the pattern).

The nmatch provided by the user is used to fill in pmatch only (up to that),
but "our" buffers are sized exactly as needed to avoid oversized allocations
or PCRE allocating by itself.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1897244 13f79535-47bb-0310-9956-ffa450edef68
2022-01-20 12:16:58 +00:00
d3941e5eb6 Follow up to r1897240: APR_HAS_THREAD_LOCAL wants #ifdef instead of #if.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1897241 13f79535-47bb-0310-9956-ffa450edef68
2022-01-20 11:24:59 +00:00
747df57e08 ap_regex: Use Thread Local Storage (if efficient) to avoid allocations.
PCRE2 wants an opaque context by providing the API to allocate and free it, so
to minimize these calls we maintain one opaque context per thread (in Thread
Local Storage, TLS) grown as needed, and while at it we do the same for PCRE1
ints vectors. Note that this requires a fast TLS mechanism to be worth it,
which is the case of apr_thread_data_get/set() from/to apr_thread_current()
when APR_HAS_THREAD_LOCAL; otherwise we'll do the allocation and freeing for
each ap_regexec().

The small stack vector is used for PCRE1 && !APR_HAS_THREAD_LOCAL only now.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1897240 13f79535-47bb-0310-9956-ffa450edef68
2022-01-20 11:09:34 +00:00
c8f486d716 Follow up to r1873941: define AP_REG_NO_DEFAULT for raw ap_regcomp() usage.
This avoids having to define AP_REG_NO_* for each APR_REG_* specific option,
thus replacing AP_REG_NO_DOTALL introduced lately.

For ap_rxplus_compile() and mod_substitute where default AP_REG_DOTALL is not
suitable, let's use:
    AP_REG_NO_DEFAULT | ap_regcomp_get_default_cflags() & AP_REG_DOLLAR_ENDONLY
to keep the default AP_REG_DOLLAR_ENDONLY unless RegexDefaultOptions unsets it.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1874090 13f79535-47bb-0310-9956-ffa450edef68
2020-02-16 23:08:32 +00:00
85760859ca Fix spelling errors found by codespell. [skip ci]
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1873985 13f79535-47bb-0310-9956-ffa450edef68
2020-02-13 18:15:57 +00:00
b6dd2f55dc don't use DOTALL from mod_substitute which leaves \n at the end of the line.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1873941 13f79535-47bb-0310-9956-ffa450edef68
2020-02-12 13:36:40 +00:00
81313af01a factor out default regex flags
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1873747 13f79535-47bb-0310-9956-ffa450edef68
2020-02-07 17:08:41 +00:00
905b4af030 set PCRE_DOTALL by default
Submitted by ylavic



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1864192 13f79535-47bb-0310-9956-ffa450edef68
2019-08-02 01:31:28 +00:00
d771a84dbf Correctly identify origin of util_pcre.c/ap_regex.h as pcreposix[.ch]
and correct LICENSE/NOTICE to match.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1824973 13f79535-47bb-0310-9956-ffa450edef68
2018-02-21 14:56:01 +00:00
ec8855dcfd Follow up to r1824339: s/strcasecmp/ap_cstr_casecmp/ as suggested by Ruediger.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1824439 13f79535-47bb-0310-9956-ffa450edef68
2018-02-16 10:01:13 +00:00
2c21956d95 regex: Allow to configure global/default options for regexes.
Like caseless matching or extended format, which may be useful as default
behaviour the whole configuration.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1824339 13f79535-47bb-0310-9956-ffa450edef68
2018-02-15 17:53:24 +00:00
08ddf7ad0a ap_expr: open string expressions to the <word>.
Introduces the syntax "%{:<word>:}", borrowed from the <var>'s one, and which
likewise can be embedded anywhere in a string expression (the same reserved
character ':' gets reused in an unambiguous manner).

This allows the two types of expressions (boolean and string) to now share
fully the same language set, namely: strings, lists, vars, regexes, backrefs,
functions with multiple or complex arguments, and especially combinations
thereof.

Most of them were reserved to boolean expressions only, while complex string
constructions can also benefit to, well, strings. The <word> construct allows
that (say the syntax "%{:<word>:}" looks like a temporary variable constructed
in a string).

Since string expressions may now have to deal with lists (arrays), they also
need a way to produce/extract strings from list and vice versa. This can be
done with the new "join" and "split" operators, while the new substitution
regexes (like "s/<pattern>/<substitute>/<flags>") may be used to manipulate
strings in place. All this of course available for both string and boolean
expressions.

Tests and doc updates upcoming..



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1810605 13f79535-47bb-0310-9956-ffa450edef68
2017-10-02 21:57:26 +00:00
cdc1d3a938 With the changes of api from pcre 8.x to 10.x, do not presume that the internal
ovector will be created to accept greater than nmatch elements for processing.
Allocate enough elts in all circumstances for pcre2api.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1773882 13f79535-47bb-0310-9956-ffa450edef68
2016-12-12 21:57:06 +00:00
12cfcf08ff Replace PCRE with PCRE2 where it is available.
This patch removes the needless assignment of re_erroffset in the conf pool
by the worker threads; such mistakes break the shared copy-on-write pages of
memory that should have remained common between all httpd worker processes.

Two de-optimizations are inherent in this patch, the former ovector-on-stack
opportunity is lost unless implemented as a new general context. Safer that
we either create a new general context using pool allocation, or recycle a
per pool or per thread match_data buffer of some arbitrary 10 elts or so.

Submitted by: wrowe, Petr Pisar <ppisar@redhat.com>


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1773454 13f79535-47bb-0310-9956-ffa450edef68
2016-12-09 19:06:06 +00:00
700dd72569 Re-introduce check for sufficient PCRE version.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1612945 13f79535-47bb-0310-9956-ffa450edef68
2014-07-23 21:15:06 +00:00
8e18f1a5e9 Add compiled and loaded PCRE version numbers
to "httpd -V" output and to mod_info page.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1612934 13f79535-47bb-0310-9956-ffa450edef68
2014-07-23 19:53:22 +00:00
165f9ffcdd Check for correct minimum PCRE version in configure,
do not check in source code.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1612921 13f79535-47bb-0310-9956-ffa450edef68
2014-07-23 19:01:45 +00:00
0d2710e0d5 Clarify comment.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1612653 13f79535-47bb-0310-9956-ffa450edef68
2014-07-22 19:29:08 +00:00
8feaa1f1e3 And use #error if we get past configure...
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1579267 13f79535-47bb-0310-9956-ffa450edef68
2014-03-19 15:45:42 +00:00
fea24799cf * Only use PCRE_DUPNAMES if it is present (only in more recent versions of PCRE)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1564439 13f79535-47bb-0310-9956-ffa450edef68
2014-02-04 19:39:18 +00:00
4fecd089c4 Add a "MATCH_" prefix to variables set within
LocationMatch/DirectoryMatch/FilesMatch.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1555266 13f79535-47bb-0310-9956-ffa450edef68
2014-01-03 22:26:55 +00:00
43e022f007 core: Support named groups and backreferences within the LocationMatch,
DirectoryMatch, FilesMatch and ProxyMatch directives.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1554300 13f79535-47bb-0310-9956-ffa450edef68
2013-12-30 19:50:52 +00:00
a1b0be3dcb Make ap_regcomp() return AP_REG_ESPACE if out of memory. Make ap_pregcomp()
abort if out of memory.

This raises the minimum PCRE requirement to version 6.0, released in 2005.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1343109 13f79535-47bb-0310-9956-ffa450edef68
2012-05-27 21:40:00 +00:00
0415804814 BZ 52623: Fix building against PCRE 8.30.
PCRE dropped support for pcre_info() which is
deprecated since a long time. Use pcre_fullinfo()
instead, which exists since version 3.0 of PCRE.

Patch provided by Ruediger Pluem.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1243176 13f79535-47bb-0310-9956-ffa450edef68
2012-02-11 22:45:37 +00:00
427c85bd23 Cleanup effort in prep for GA push:
Trim trailing whitespace... no func change



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1174751 13f79535-47bb-0310-9956-ffa450edef68
2011-09-23 13:39:32 +00:00
5a225df5a3 Change the indentation to resemble the rest of the project. No code change.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1125816 13f79535-47bb-0310-9956-ffa450edef68
2011-05-21 20:55:46 +00:00
63366c900b Add ap_regexec_len() function that works with non-null-terminated
strings.

PR: 51231
Submitted by: Yehezkel Horowitz <horowity checkpoint com>, Stefan Fritsch


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1125802 13f79535-47bb-0310-9956-ffa450edef68
2011-05-21 20:34:05 +00:00
083e4c6925 * server/util_pcre.c (ap_regerror): Use passed-in buffer size rather
than the size of a pointer.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1095448 13f79535-47bb-0310-9956-ffa450edef68
2011-04-20 16:17:44 +00:00
d4963eadb1 Introduce ap_rxplus class: higher-level regexps supporting perl-style
regexp operations.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@999533 13f79535-47bb-0310-9956-ffa450edef68
2010-09-21 18:42:20 +00:00
02dc2d45cf Code cleanup: replace strncpy by apr_cpystrn or apr_pstrmemdup
Submitted by: Takashi Sato <takashi lans tv com>
PR: 43432


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@981086 13f79535-47bb-0310-9956-ffa450edef68
2010-07-31 20:08:44 +00:00
34487c8eb9 revert last change
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@395421 13f79535-47bb-0310-9956-ffa450edef68
2006-04-19 22:52:45 +00:00
ebe24d48c7 Update the last year of copyright.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@395229 13f79535-47bb-0310-9956-ffa450edef68
2006-04-19 12:23:42 +00:00