Skip to content

Commit

Permalink
SECURITY Backporting MySQLDatabase->addslashes() to use mysql_real_es…
Browse files Browse the repository at this point in the history
…cape_string() instead of the non-multibyte-safe addslashes() PHP function, and using it in Convert::raw2sql()
  • Loading branch information
chillu committed Sep 15, 2011
1 parent b37836f commit ca78784
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 1 addition & 2 deletions core/Convert.php
Expand Up @@ -104,9 +104,8 @@ static function raw2sql($val) {
if(is_array($val)) {
foreach($val as $k => $v) $val[$k] = self::raw2sql($v);
return $val;

} else {
return addslashes($val);
return DB::getConn()->addslashes($val);
}
}

Expand Down
8 changes: 8 additions & 0 deletions core/model/Database.php
Expand Up @@ -111,6 +111,14 @@ protected abstract function fieldList($table);
*/
protected abstract function tableList();

/**
* Returns an escaped string.
*
* @param string
* @return string - escaped string
*/
abstract function addslashes($val);

/**
* The table list, generated by the tableList() function.
* Used by the requireTable() function.
Expand Down
7 changes: 7 additions & 0 deletions core/model/MySQLDatabase.php
Expand Up @@ -400,6 +400,13 @@ function databaseError($msg, $errorLevel = E_USER_ERROR) {

user_error($msg, $errorLevel);
}

/*
* This will return text which has been escaped in a database-friendly manner.
*/
function addslashes($value){
return mysql_real_escape_string($value, $this->dbConn);
}
}

/**
Expand Down

0 comments on commit ca78784

Please sign in to comment.