Skip to content
Closed
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 Sources/Subs-Db-mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ 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*?(?<![\'\\\\])\'~',
'~\'\X*?\'~s',
'~\s+~s',
'~/\*!40001 SQL_NO_CACHE \*/~',
'~/\*!40000 USE INDEX \([A-Za-z\_]+?\) \*/~',
Expand Down Expand Up @@ -417,7 +417,9 @@ 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)));
// Clear out escaped backslashes & single quotes first, to make it simpler to ID & remove string literals
$clean = str_replace(array('\\\\', '\\\''), array('', ''), $db_string);
$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $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
6 changes: 4 additions & 2 deletions Sources/Subs-Db-postgresql.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ 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*?(?<![\'\\\\])\'~',
'~\'\X*?\'~s',
'~\s+~s',
'~/\*!40001 SQL_NO_CACHE \*/~',
'~/\*!40000 USE INDEX \([A-Za-z\_]+?\) \*/~',
Expand Down Expand Up @@ -415,7 +415,9 @@ 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)));
// Clear out escaped single quotes first, to make it simpler to ID & remove string literals
$clean = str_replace('\'\'', '', $db_string);
$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $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