Skip to content

Commit

Permalink
Correctly escape variables for sql statements
Browse files Browse the repository at this point in the history
  • Loading branch information
GodMod committed Nov 6, 2019
1 parent f42293b commit ca90739
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
6 changes: 3 additions & 3 deletions admin/manage_user_groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -676,9 +676,9 @@ private function switch_upd_ins($auth_id, $group_id){
$sql = "SELECT o.auth_value
FROM __auth_options o, __auth_groups u
WHERE (u.auth_id = o.auth_id)
AND (u.group_id='".$group_id."')
AND u.auth_id='".$auth_id."'";
$objQuery = $this->db->query($sql);
AND (u.group_id=?)
AND u.auth_id=?";
$objQuery = $this->db->prepare($sql)->execute($group_id, $auth_id);

if ( $objQuery && $objQuery->numRows > 0 )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,22 @@ public function get_id_list($raids_only=false, $start_date = 0, $end_date = PHP_
if(($start_date != 0) || ($end_date != PHP_INT_MAX)){
$start_date = $this->time->newtime($start_date, '00:00', false);
$end_date = ($end_date != PHP_INT_MAX) ? $this->time->newtime($end_date, '23:59', false) : $end_date;

$sqlstring = "SELECT id FROM __calendar_events WHERE";
$sqlstring .= (is_array($idfilter)) ? ' (calendar_id IN ('.implode(",", $idfilter).')) AND' : '';

$sqlstring .= (is_array($idfilter)) ? ' (calendar_id IN ('.implode(",", $this->db->escapeParams($idfilter)).')) AND' : '';
$sqlstring .= " ((timestamp_start BETWEEN ".$this->db->escapeString($start_date)." AND ".$this->db->escapeString($end_date).") OR (timestamp_end BETWEEN ".$this->db->escapeString($start_date)." AND ".$this->db->escapeString($end_date)."))";

// apply the filtering
switch($filter){
case 'mine':
$sqlstring .= " AND creator=".$this->user->data['user_id'];
$sqlstring .= " AND creator=".$this->db->escapeString($this->user->data['user_id']);
break;
case 'past':
$sqlstring .= " AND timestamp_end<".$this->time->time;
$sqlstring .= " AND timestamp_end<".$this->db->escapeString($this->time->time);
break;
case 'future':
$sqlstring .= " AND timestamp_end>".$this->time->time;
$sqlstring .= " AND timestamp_end>".$this->db->escapeString($this->time->time);
break;
default: $sqlstring .= "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ public function sort($id_list, $tag, $direction = 'asc', $params = array( ), $id
if(!method_exists($this, 'get_'.$tag) || $tag == 'viewicon' || $tag == 'value' || $tag == 'id_list' || $tag == 'lastxlogs') return $id_list;

$direction = ($direction == 'asc') ? 'ASC' : 'DESC';
if($tag == 'user') {
if($tag == 'user') {
$objQuery = $this->db->prepare("SELECT log_id FROM __logs WHERE log_id :in ORDER BY username ".$direction.";")->in($id_list)->execute();
} else {
if(!in_array($tag, array('id', 'date', 'value', 'ipaddress', 'sid', 'result', 'tag', 'plugin', 'flag', 'record', 'record_id'))) return false;

$objQuery = $this->db->prepare("SELECT log_id FROM __logs WHERE log_id :in ORDER BY log_".$tag." ".$direction.";")->in($id_list)->execute();
}
$id_list = array();
Expand Down
7 changes: 6 additions & 1 deletion libraries/dbal/dbal.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,11 @@ public function escapeString($strString){
return $objStatement->escapeString($strString);
}

public function escapeParams($arrParams){
$objStatement = $this->createStatement($this->resConnection, $this->strTablePrefix, $this->strDebugPrefix,$this->blnDisableAutocommit);
return $objStatement->escapeParams($arrParams);
}

public function replaceTablePrefix($strQuery){
$strQuery = preg_replace("/([\s|`|'])__([a-zA-Z])/", '$1'.$this->strTablePrefix.'$2', $strQuery);
return $strQuery;
Expand Down Expand Up @@ -892,7 +897,7 @@ protected function replaceWildcards($arrParams){
* @param array
* @return array
*/
protected function escapeParams($arrParams, $blnIgnoreKeys=false){
public function escapeParams($arrParams, $blnIgnoreKeys=false){
foreach ($arrParams as $k=>$v)
{
switch (gettype($v))
Expand Down

0 comments on commit ca90739

Please sign in to comment.