Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-pcre2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
libvmod-pcre2
Commits
429725e1
Commit
429725e1
authored
Feb 24, 2017
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reduce repetition in pcre2 error message reporting
parent
c378fa6f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
63 deletions
+49
-63
vmod_pcre2.c
src/vmod_pcre2.c
+49
-63
No files found.
src/vmod_pcre2.c
View file @
429725e1
...
...
@@ -110,14 +110,32 @@ errmsg(VRT_CTX, const char *fmt, ...)
va_end
(
args
);
}
static
inline
int
get_pcre2_errmsg
(
struct
ws
*
const
restrict
ws
,
int
errcode
,
c
har
*
restrict
*
const
restrict
buf
)
static
void
report_pcre2_err
(
VRT_CTX
,
int
errcode
,
const
char
*
const
restrict
msg
,
c
onst
char
*
const
restrict
post
)
{
unsigned
bytes
=
WS_Reserve
(
ws
,
0
);
*
buf
=
WS_Front
(
ws
);
return
pcre2_get_error_message
(
errcode
,
(
PCRE2_UCHAR
*
)
*
buf
,
(
PCRE2_SIZE
)
bytes
);
int
ret
;
uintptr_t
snap
=
WS_Snapshot
(
ctx
->
ws
);
unsigned
bytes
=
WS_Reserve
(
ctx
->
ws
,
0
);
char
*
buf
=
WS_Front
(
ctx
->
ws
);
ret
=
pcre2_get_error_message
(
errcode
,
(
PCRE2_UCHAR
*
)
buf
,
(
PCRE2_SIZE
)
bytes
);
if
(
ret
==
PCRE2_ERROR_BADDATA
)
{
WS_ReleaseP
(
ctx
->
ws
,
buf
);
VERR
(
ctx
,
"%s (unknown error code)%s"
,
msg
,
post
);
}
else
if
(
ret
==
PCRE2_ERROR_NOMEMORY
)
{
WS_Release
(
ctx
->
ws
,
strlen
(
buf
)
+
1
);
VERR
(
ctx
,
"%s: %s (truncated error message)%s"
,
msg
,
buf
,
post
);
}
else
{
WS_Release
(
ctx
->
ws
,
ret
);
VERR
(
ctx
,
"%s: %s%s"
,
msg
,
buf
,
post
);
}
WS_Reset
(
ctx
->
ws
,
snap
);
}
/* Event function */
...
...
@@ -293,26 +311,17 @@ vmod_regex__init(VRT_CTX, struct vmod_pcre2_regex **regexp,
code
=
pcre2_compile
((
PCRE2_SPTR
)
pattern
,
PCRE2_ZERO_TERMINATED
,
options
,
&
err_code
,
&
err_offset
,
ccontext
);
if
(
code
==
NULL
)
{
char
*
buf
;
char
*
msg
,
*
offset_msg
;
uintptr_t
snap
=
WS_Snapshot
(
ctx
->
ws
);
ret
=
get_pcre2_errmsg
(
ctx
->
ws
,
err_code
,
&
buf
);
if
(
ret
==
PCRE2_ERROR_BADDATA
)
{
WS_ReleaseP
(
ctx
->
ws
,
buf
);
VERR
(
ctx
,
"Cannot compile '%s' in %s constructor "
"(unknown error code)"
,
pattern
,
vcl_name
);
}
else
if
(
ret
==
PCRE2_ERROR_NOMEMORY
)
{
WS_Release
(
ctx
->
ws
,
strlen
(
buf
)
+
1
);
VERR
(
ctx
,
"Cannot compile '%s' in %s constructor: %s"
"(truncated error message) at offset %zu"
,
pattern
,
vcl_name
,
err_offset
);
}
else
{
WS_Release
(
ctx
->
ws
,
ret
);
VERR
(
ctx
,
"Cannot compile '%s' in %s constructor: %s "
"at offset %zu"
,
pattern
,
vcl_name
,
buf
,
err_offset
);
}
if
((
msg
=
WS_Printf
(
ctx
->
ws
,
"Cannot compile '%s' in %s constructor"
,
pattern
,
vcl_name
))
==
NULL
)
msg
=
""
;
if
((
offset_msg
=
WS_Printf
(
ctx
->
ws
,
" at offset %zu"
,
err_offset
))
==
NULL
)
offset_msg
=
""
;
report_pcre2_err
(
ctx
,
err_code
,
msg
,
offset_msg
);
WS_Reset
(
ctx
->
ws
,
snap
);
pcre2_compile_context_free
(
ccontext
);
return
;
...
...
@@ -323,27 +332,14 @@ vmod_regex__init(VRT_CTX, struct vmod_pcre2_regex **regexp,
options
|=
PCRE2_JIT_COMPLETE
;
ret
=
pcre2_jit_compile
(
code
,
options
);
if
(
ret
!=
0
)
{
char
*
buf
;
char
*
msg
;
uintptr_t
snap
=
WS_Snapshot
(
ctx
->
ws
);
ret
=
get_pcre2_errmsg
(
ctx
->
ws
,
ret
,
&
buf
);
if
(
ret
==
PCRE2_ERROR_BADDATA
)
{
WS_ReleaseP
(
ctx
->
ws
,
buf
);
VERR
(
ctx
,
"Cannot jit-compile '%s' in %s "
"constructor (unknown error code)"
,
pattern
,
vcl_name
);
}
else
if
(
ret
==
PCRE2_ERROR_NOMEMORY
)
{
WS_Release
(
ctx
->
ws
,
strlen
(
buf
)
+
1
);
VERR
(
ctx
,
"Cannot jit-compile '%s' in %s "
"constructor: %s (truncated error message)"
,
pattern
,
vcl_name
);
}
else
{
WS_Release
(
ctx
->
ws
,
ret
);
VERR
(
ctx
,
"Cannot jit-compile '%s' in %s "
"constructor: %s "
,
pattern
,
vcl_name
,
buf
);
}
if
((
msg
=
WS_Printf
(
ctx
->
ws
,
"Cannot jit-compile '%s' "
"in %s constructor"
,
pattern
,
vcl_name
))
==
NULL
)
msg
=
""
;
report_pcre2_err
(
ctx
,
ret
,
msg
,
""
);
WS_Reset
(
ctx
->
ws
,
snap
);
pcre2_compile_context_free
(
ccontext
);
return
;
...
...
@@ -390,6 +386,8 @@ vmod_regex_match(VRT_CTX, struct vmod_pcre2_regex *regex,
struct
vmod_priv
*
match_task
=
NULL
;
struct
match_call
*
match_opts
;
int
ret
;
char
*
msg
;
uintptr_t
snap
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
regex
,
VMOD_PCRE2_REGEX_MAGIC
);
...
...
@@ -504,23 +502,11 @@ vmod_regex_match(VRT_CTX, struct vmod_pcre2_regex *regex,
if
(
ret
>=
0
)
return
1
;
char
*
buf
;
uintptr_t
snap
=
WS_Snapshot
(
ctx
->
ws
);
ret
=
get_pcre2_errmsg
(
ctx
->
ws
,
ret
,
&
buf
);
if
(
ret
==
PCRE2_ERROR_BADDATA
)
{
WS_ReleaseP
(
ctx
->
ws
,
buf
);
VERR
(
ctx
,
"in %s.match() (unknown error code)"
,
regex
->
vcl_name
);
}
else
if
(
ret
==
PCRE2_ERROR_NOMEMORY
)
{
WS_Release
(
ctx
->
ws
,
strlen
(
buf
)
+
1
);
VERR
(
ctx
,
"in %s.match(): %s (truncated error message)"
,
regex
->
vcl_name
,
buf
);
}
else
{
WS_Release
(
ctx
->
ws
,
ret
);
VERR
(
ctx
,
"in %s.match(): %s "
,
regex
->
vcl_name
,
buf
);
}
snap
=
WS_Snapshot
(
ctx
->
ws
);
if
((
msg
=
WS_Printf
(
ctx
->
ws
,
"in %s.match()"
,
regex
->
vcl_name
))
==
NULL
)
msg
=
""
;
report_pcre2_err
(
ctx
,
ret
,
msg
,
""
);
WS_Reset
(
ctx
->
ws
,
snap
);
return
0
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment