Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/pcre2_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2301,8 +2301,9 @@ is available. */
#define _pcre2_is_newline PCRE2_SUFFIX(_pcre2_is_newline_)
#define _pcre2_jit_free_rodata PCRE2_SUFFIX(_pcre2_jit_free_rodata_)
#define _pcre2_jit_free PCRE2_SUFFIX(_pcre2_jit_free_)
#define _pcre2_jit_get_size PCRE2_SUFFIX(_pcre2_jit_get_size_)
#define _pcre2_jit_check_exec PCRE2_SUFFIX(_pcre2_jit_check_exec_)
#define _pcre2_jit_get_target PCRE2_SUFFIX(_pcre2_jit_get_target_)
#define _pcre2_jit_get_size PCRE2_SUFFIX(_pcre2_jit_get_size_)
#define _pcre2_memctl_malloc PCRE2_SUFFIX(_pcre2_memctl_malloc_)
#define _pcre2_ord2utf PCRE2_SUFFIX(_pcre2_ord2utf_)
#define _pcre2_script_run PCRE2_SUFFIX(_pcre2_script_run_)
Expand Down Expand Up @@ -2330,8 +2331,9 @@ extern BOOL _pcre2_is_newline(PCRE2_SPTR, uint32_t, PCRE2_SPTR,
uint32_t *, BOOL);
extern void _pcre2_jit_free_rodata(void *, void *);
extern void _pcre2_jit_free(void *, pcre2_memctl *);
extern size_t _pcre2_jit_get_size(void *);
const char * _pcre2_jit_get_target(void);
extern size_t _pcre2_jit_get_size(void *);
extern BOOL _pcre2_jit_check_exec(void *, uint32_t);
extern void * _pcre2_memctl_malloc(size_t, pcre2_memctl *);
extern unsigned int _pcre2_ord2utf(uint32_t, PCRE2_UCHAR *);
extern BOOL _pcre2_script_run(PCRE2_SPTR, PCRE2_SPTR, BOOL);
Expand Down
25 changes: 25 additions & 0 deletions src/pcre2_jit_misc_inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,29 @@ return executable_sizes[0] + executable_sizes[1] + executable_sizes[2];
#endif
}

/*************************************************
* Checks function compilation *
*************************************************/

BOOL
PRIV(jit_check_exec)(void *executable_jit, uint32_t options)
{
#ifndef SUPPORT_JIT
(void)executable_jit;
(void)options;
return FALSE;
#else /* SUPPORT_JIT */
executable_functions *functions = (executable_functions *)executable_jit;
int index = 0;

if ((options & PCRE2_PARTIAL_HARD) != 0)
index = 2;
else if ((options & PCRE2_PARTIAL_SOFT) != 0)
index = 1;

return functions->executable_funcs[index] != NULL;
#endif
}


/* End of pcre2_jit_misc_inc.h */
65 changes: 26 additions & 39 deletions src/pcre2_match.c
Original file line number Diff line number Diff line change
Expand Up @@ -7006,7 +7006,7 @@ PCRE2_SPTR start_partial;
PCRE2_SPTR match_partial;

#ifdef SUPPORT_JIT
BOOL use_jit;
BOOL use_jit = FALSE;
#endif

/* This flag is needed even when Unicode is not supported for convenience
Expand All @@ -7018,9 +7018,6 @@ BOOL utf = FALSE;
BOOL ucp = FALSE;
BOOL allow_invalid;
uint32_t fragment_options = 0;
#ifdef SUPPORT_JIT
BOOL jit_checked_utf = FALSE;
#endif
#endif /* SUPPORT_UNICODE */

PCRE2_SIZE frame_size;
Expand Down Expand Up @@ -7088,8 +7085,9 @@ JIT executable instead of the rest of this function. Most options must be set
at compile time for the JIT code to be usable. */

#ifdef SUPPORT_JIT
use_jit = (re->executable_jit != NULL &&
(options & ~PUBLIC_JIT_MATCH_OPTIONS) == 0);
if (re->executable_jit != NULL &&
(options & ~PUBLIC_JIT_MATCH_OPTIONS) == 0)
use_jit = PRIV(jit_check_exec)(re->executable_jit, options);
#endif

/* Initialize UTF/UCP parameters. */
Expand Down Expand Up @@ -7151,7 +7149,6 @@ if (use_jit)
#ifdef SUPPORT_UNICODE
if (utf && (options & PCRE2_NO_UTF_CHECK) == 0 && !allow_invalid)
{

/* For 8-bit and 16-bit UTF, check that the first code unit is a valid
character start. */

Expand Down Expand Up @@ -7204,7 +7201,6 @@ if (use_jit)
match_data->startchar += start_match - subject;
return match_data->rc = rc;
}
jit_checked_utf = TRUE;
}
#endif /* SUPPORT_UNICODE */

Expand All @@ -7213,31 +7209,30 @@ if (use_jit)

rc = pcre2_jit_match(code, subject, length, start_offset, options,
match_data, mcontext);
if (rc != PCRE2_ERROR_JIT_BADOPTION)
PCRE2_ASSERT(rc != PCRE2_ERROR_JIT_BADOPTION);

match_data->options = original_options;
if (rc >= 0 && (options & PCRE2_COPY_MATCHED_SUBJECT) != 0)
{
match_data->options = original_options;
if (rc >= 0 && (options & PCRE2_COPY_MATCHED_SUBJECT) != 0)
if (length != 0)
{
if (length != 0)
{
match_data->subject = match_data->memctl.malloc(CU2BYTES(length),
match_data->memctl.memory_data);
if (match_data->subject == NULL)
return match_data->rc = PCRE2_ERROR_NOMEMORY;
memcpy((void *)match_data->subject, subject, CU2BYTES(length));
}
else
match_data->subject = NULL;
match_data->flags |= PCRE2_MD_COPIED_SUBJECT;
match_data->subject = match_data->memctl.malloc(CU2BYTES(length),
match_data->memctl.memory_data);
if (match_data->subject == NULL)
return match_data->rc = PCRE2_ERROR_NOMEMORY;
memcpy((void *)match_data->subject, subject, CU2BYTES(length));
}
else
{
/* When pcre2_jit_match sets the subject, it doesn't know what the
original passed-in pointer was. */
if (match_data->subject != NULL) match_data->subject = original_subject;
}
return rc;
match_data->subject = NULL;
match_data->flags |= PCRE2_MD_COPIED_SUBJECT;
}
else
{
/* When pcre2_jit_match sets the subject, it doesn't know what the
original passed-in pointer was. */
if (match_data->subject != NULL) match_data->subject = original_subject;
}
return rc;
}
#endif /* SUPPORT_JIT */

Expand All @@ -7250,12 +7245,8 @@ this. */

mb->check_subject = subject;

/* If a UTF subject string was not checked for validity in the JIT code above,
check it here, and handle support for invalid UTF strings. The check above
happens only when invalid UTF is not supported and PCRE2_NO_CHECK_UTF is unset.
If we get here in those circumstances, it means the subject string is valid,
but for some reason JIT matching was not successful. There is no need to check
the subject again.
/* Check the validity of UTF subject strings. The check happens only when
PCRE2_NO_CHECK_UTF is unset.

We check only the portion of the subject that might be be inspected during
matching - from the offset minus the maximum lookbehind to the given length.
Expand All @@ -7267,11 +7258,7 @@ Note also that support for invalid UTF forces a check, overriding the setting
of PCRE2_NO_CHECK_UTF. */

#ifdef SUPPORT_UNICODE
if (utf &&
#ifdef SUPPORT_JIT
!jit_checked_utf &&
#endif
((options & PCRE2_NO_UTF_CHECK) == 0 || allow_invalid))
if (utf && ((options & PCRE2_NO_UTF_CHECK) == 0 || allow_invalid))
{
#if PCRE2_CODE_UNIT_WIDTH != 32
BOOL skipped_bad_start = FALSE;
Expand Down
Loading