Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop mysql syntax error exceptions #4312

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add manually allocated jit stack for pcre expressions to avoid PCRE_E…
…RROR_JIT_STACKLIMIT when calling pcre_exec()
  • Loading branch information
mgottein committed Nov 13, 2014
commit 2ac4a270a7fc13531dbbf41581c3311a76be3ee0
10 changes: 10 additions & 0 deletions hphp/runtime/base/preg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ void PCREglobals::onSessionExit() {
smart::vector<const pcre_cache_entry*>().swap(m_overflow);
}

PCREglobals::PCREglobals() {
m_jit_stack = pcre_jit_stack_alloc(32768, 524288);
}

PCREglobals::~PCREglobals() {
pcre_jit_stack_free(m_jit_stack);
onSessionExit();
}

Expand Down Expand Up @@ -196,6 +201,10 @@ static __thread pcre_extra t_extra_data;
// The last pcre error code is available for the whole thread.
static __thread int t_last_error_code;

static pcre_jit_stack *alloc_jit_stack(void* data) {
return s_pcre_globals->m_jit_stack;
}

namespace {

template<bool useSmartFree = false>
Expand Down Expand Up @@ -443,6 +452,7 @@ pcre_get_compiled_regex_cache(const String& regex) {
if (extra) {
extra->flags |= PCRE_EXTRA_MATCH_LIMIT |
PCRE_EXTRA_MATCH_LIMIT_RECURSION;
pcre_assign_jit_stack(extra, alloc_jit_stack, nullptr);
}
if (error != nullptr) {
try {
Expand Down
3 changes: 2 additions & 1 deletion hphp/runtime/base/preg.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ class pcre_cache_entry {

class PCREglobals {
public:
PCREglobals() { }
PCREglobals();
~PCREglobals();
void cleanupOnRequestEnd(const pcre_cache_entry* ent);
void onSessionExit();
// pcre ini_settings
int64_t m_preg_backtrace_limit;
int64_t m_preg_recursion_limit;
pcre_jit_stack *m_jit_stack;
private:
smart::vector<const pcre_cache_entry*> m_overflow;
};
Expand Down