Skip to content

Commit

Permalink
Explicitly create stack for compiled regexps
Browse files Browse the repository at this point in the history
Summary: PMA_Operations_Test::testGetHtmlForCopyDatabase
PMA_Operations_Test::testGetHtmlForPartitionMaintenance
Closes #4239

Reviewed By: @paulbiss

Differential Revision: D1679090

Signature: t1:1679090:1416463904:898d4d7200b2d809241484c6c92965485ed26627
  • Loading branch information
mgottein authored and hhvm-bot committed Nov 20, 2014
1 parent 54dbd6c commit fbdd08d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
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 @@ -212,6 +217,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 @@ -459,6 +468,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
17 changes: 17 additions & 0 deletions hphp/test/slow/ext_preg/preg_match_stack.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

$str = <<<'EOD'
<div class="operations_half_width clearfloat"><form id="copy_db_form" class="ajax" method="post" action="db_operations.php"onsubmit="return emptyFormElements(this, 'newname')"><input type="hidden" name="db_collation" value="db1" />
<input type="hidden" name="db_copy" value="true" />
<input type="hidden" name="db" value="pma" /><input type="hidden" name="lang" value="en" /><input type="hidden" name="token" value="token" /><fieldset><legend><img src="themes/dot.gif" title="" alt="" class="icon ic_b_edit" />Copy database to:</legend><input type="text" name="newname" size="30" class="textfield" value="" required="required" /><br /><input type="radio" name="what" id="what_structure" value="structure" />
<label for="what_structure">Structure only</label><br />
<input type="radio" name="what" id="what_data" value="data" checked="checked" />
<label for="what_data">Structure and data</label><br />
<input type="radio" name="what" id="what_dataonly" value="dataonly" />
<label for="what_dataonly">Data only</label><br />
<input type="checkbox" name="create_database_before_copying" value="1" id="checkbox_create_database_before_copying"checked="checked" /><label for="checkbox_create_database_before_copying">CREATE DATABASE before copying</label><br /><input type="checkbox" name="drop_if_exists" value="true"id="checkbox_drop" /><label for="checkbox_drop">Add DROP TABLE / DROP VIEW</label><br /><input type="checkbox" name="sql_auto_increment" value="1" checked="checked" id="checkbox_auto_increment" /><label for="checkbox_auto_increment">Add AUTO_INCREMENT value</label><br /><input type="checkbox" name="add_constraints" value="1"id="checkbox_constraints" /><label for="checkbox_constraints">Add constraints</label><br /><input type="checkbox" name="switch_to_new" value="true"id="checkbox_switch"/><label for="checkbox_switch">Switch to copied database</label></fieldset><fieldset class="tblFooters"><input type="submit" name="submit_copy" value="Go" /></fieldset></form></div>
EOD;

$pattern = "/.*db_operations.php(.|[\\n])*db_copy([\\n]|.)*Copy database to.*/m";

var_dump(preg_match($pattern, $str));
1 change: 1 addition & 0 deletions hphp/test/slow/ext_preg/preg_match_stack.php.expectf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int(1)

0 comments on commit fbdd08d

Please sign in to comment.