DatabaseConnection::filterComment
protected function DatabaseConnection::filterComment
protected DatabaseConnection::filterComment($comment = '')
Sanitize a query comment string.
Ensure a query comment does not include strings such as "* /" that might terminate the comment early. This avoids SQL injection attacks via the query comment. The comment strings in this example are separated by a space to avoid PHP parse errors.
For example, the comment:
db_update('example') ->condition('id', $id) ->fields(array('field2' => 10)) ->comment('Exploit * / DROP TABLE node; --') ->execute()
Would result in the following SQL statement being generated:
"/ * Exploit * / DROP TABLE node; -- * / UPDATE example SET field2=..."
Unless the comment is sanitised first, the SQL server would drop the node table and ignore the rest of the SQL statement.
Parameters
$comment: A query comment string.
Return value
A sanitized version of the query comment string.
File
- includes/database/database.inc, line 628
- Core systems for the database layer.
Class
- DatabaseConnection
- Base Database API class.
Code
protected function filterComment($comment = '') { return strtr($comment, array('*' => ' * ')); }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!database!database.inc/function/DatabaseConnection::filterComment/7.x