Commit 8f7a8518 authored by Geoff Simmons's avatar Geoff Simmons

Don't copy the subject string if it's already in workspace.

parent b0c33f72
Pipeline #203 skipped
......@@ -329,27 +329,22 @@ Version 2.0: compatible with Varnish 5.1
LIMITATIONS
===========
Regular expressions passed into the constructor and into ``match_dyn``
are compiled at run-time, so there are no errors at VCL compile-time
for invalid expressions. If an expression is invalid, then a
``VCL_error`` message is emitted to the Varnish log, matches always
fail, and errors in the constructor can be inspected with ``failed``
and ``error``.
The VMOD allocates memory for captured subexpressions from Varnish
workspaces, whose sizes are determined by the runtime parameters
``workspace_backend``, for calls within the ``vcl_backend_*``
subroutines, and ``workspace_client``, for the other VCL subs. The
VMOD copies the string to be matched into the workspace, along with
some overhead. For typical usage, the default workspace sizes are
probably enough; but if you are matching against many, long strings in
each client or backend context, you might need to increase the Varnish
parameters for workspace sizes. If the VMOD cannot allocate enough
workspace, then a ``VCL_error`` message is emitted, and the match
methods as well as ``backref`` will fail. (If you're just using the
regexen for matching and not to capture backrefs, then you might as
well just use the standard VCL operators ``~`` and ``!~``, and save
the workspace.)
VMOD copies the string to be matched into the workspace, if it's not
already in the workspace, and also uses workspace to save data about
backreferences.
For typical usage, the default workspace sizes are probably enough;
but if you are matching against many, long strings in each client or
backend context, you might need to increase the Varnish parameters for
workspace sizes. If the VMOD cannot allocate enough workspace, then a
``VCL_error`` message is emitted, and the match methods as well as
``backref`` will fail. (If you're just using the regexen for matching
and not to capture backrefs, then you might as well just use the
standard VCL operators ``~`` and ``!~``, and save the workspace.)
``backref`` can extract up to 10 subexpressions, in addition to the
full expression indicated by backref 0. If a ``match`` or
......
......@@ -136,8 +136,7 @@ match(VRT_CTX, vre_t *vre, VCL_STRING subject, struct vmod_priv *task)
{
ov_t *ov;
int s, nov[MAX_OV];
uintptr_t snap;
size_t cp;
size_t cp, len;
AN(vre);
if (subject == NULL)
......@@ -173,10 +172,11 @@ match(VRT_CTX, vre_t *vre, VCL_STRING subject, struct vmod_priv *task)
}
task->len = sizeof(*ov);
snap = WS_Snapshot(ctx->ws);
ov->subject = WS_Copy(ctx->ws, (const void *) subject, -1);
if (ov->subject == NULL) {
WS_Reset(ctx->ws, snap);
len = strlen(subject);
if (WS_Inside(ctx->ws, subject, subject + len))
ov->subject = subject;
else if ((ov->subject = WS_Copy(ctx->ws, (const void *) subject, len))
== NULL) {
VSLb(ctx->vsl, SLT_VCL_Error,
"vmod re: insufficient workspace");
return 0;
......
......@@ -265,27 +265,22 @@ Version 2.0: compatible with Varnish 5.1
LIMITATIONS
===========
Regular expressions passed into the constructor and into ``match_dyn``
are compiled at run-time, so there are no errors at VCL compile-time
for invalid expressions. If an expression is invalid, then a
``VCL_error`` message is emitted to the Varnish log, matches always
fail, and errors in the constructor can be inspected with ``failed``
and ``error``.
The VMOD allocates memory for captured subexpressions from Varnish
workspaces, whose sizes are determined by the runtime parameters
``workspace_backend``, for calls within the ``vcl_backend_*``
subroutines, and ``workspace_client``, for the other VCL subs. The
VMOD copies the string to be matched into the workspace, along with
some overhead. For typical usage, the default workspace sizes are
probably enough; but if you are matching against many, long strings in
each client or backend context, you might need to increase the Varnish
parameters for workspace sizes. If the VMOD cannot allocate enough
workspace, then a ``VCL_error`` message is emitted, and the match
methods as well as ``backref`` will fail. (If you're just using the
regexen for matching and not to capture backrefs, then you might as
well just use the standard VCL operators ``~`` and ``!~``, and save
the workspace.)
VMOD copies the string to be matched into the workspace, if it's not
already in the workspace, and also uses workspace to save data about
backreferences.
For typical usage, the default workspace sizes are probably enough;
but if you are matching against many, long strings in each client or
backend context, you might need to increase the Varnish parameters for
workspace sizes. If the VMOD cannot allocate enough workspace, then a
``VCL_error`` message is emitted, and the match methods as well as
``backref`` will fail. (If you're just using the regexen for matching
and not to capture backrefs, then you might as well just use the
standard VCL operators ``~`` and ``!~``, and save the workspace.)
``backref`` can extract up to 10 subexpressions, in addition to the
full expression indicated by backref 0. If a ``match`` or
......
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