Skip to content
Merged
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
16 changes: 13 additions & 3 deletions Sources/Subs-Db-mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,12 @@ function smf_db_query($identifier, $db_string, $db_values = array(), $connection

// Comments that are allowed in a query are preg_removed.
static $allowed_comments_from = array(
'~(?<![\'\\\\])\'\X*?(?<![\'\\\\])\'~',
'~\s+~s',
'~/\*!40001 SQL_NO_CACHE \*/~',
'~/\*!40000 USE INDEX \([A-Za-z\_]+?\) \*/~',
'~/\*!40100 ON DUPLICATE KEY UPDATE id_msg = \d+ \*/~',
);
static $allowed_comments_to = array(
' %s ',
' ',
'',
'',
Expand Down Expand Up @@ -417,7 +415,19 @@ function smf_db_query($identifier, $db_string, $db_values = array(), $connection
// First, we clean strings out of the query, reduce whitespace, lowercase, and trim - so we can check it over.
if (empty($modSettings['disableQueryCheck']))
{
$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $db_string)));
$clean = preg_split('/(?<![\'\\\\])\'(?![\'])/', $db_string);

for ($i = 0; $i < count($clean); $i++)
{
if ($i % 2 === 1)
$clean[$i] = ' %s ';
}

$clean = trim(strtolower(preg_replace(
$allowed_comments_from,
$allowed_comments_to,
implode('', $clean)
)));

// Comments? We don't use comments in our queries, we leave 'em outside!
if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
Expand Down
16 changes: 13 additions & 3 deletions Sources/Subs-Db-postgresql.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,14 +379,12 @@ function smf_db_query($identifier, $db_string, $db_values = array(), $connection

// Comments that are allowed in a query are preg_removed.
static $allowed_comments_from = array(
'~(?<![\'\\\\])\'\X*?(?<![\'\\\\])\'~',
'~\s+~s',
'~/\*!40001 SQL_NO_CACHE \*/~',
'~/\*!40000 USE INDEX \([A-Za-z\_]+?\) \*/~',
'~/\*!40100 ON DUPLICATE KEY UPDATE id_msg = \d+ \*/~',
);
static $allowed_comments_to = array(
' %s ',
' ',
'',
'',
Expand Down Expand Up @@ -415,7 +413,19 @@ function smf_db_query($identifier, $db_string, $db_values = array(), $connection
// First, we clean strings out of the query, reduce whitespace, lowercase, and trim - so we can check it over.
if (empty($modSettings['disableQueryCheck']))
{
$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $db_string)));
$clean = preg_split('/(?<![\'\\\\])\'(?![\'])/', $db_string);

for ($i = 0; $i < count($clean); $i++)
{
if ($i % 2 === 1)
$clean[$i] = ' %s ';
}

$clean = trim(strtolower(preg_replace(
$allowed_comments_from,
$allowed_comments_to,
implode('', $clean)
)));

// Comments? We don't use comments in our queries, we leave 'em outside!
if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
Expand Down