Skip to content
This repository has been archived by the owner on Nov 15, 2019. It is now read-only.

Commit

Permalink
[Security] Fix sql injection in modifyLimitQuery() for PgSQL and DB2
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Mar 20, 2011
1 parent 728e669 commit fcaa632
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/Doctrine/Connection/Db2.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function modifyLimitQuery($query, $limit = false, $offset = false, $isMan
return $query; return $query;


if ($offset == 0) { if ($offset == 0) {
return $query . ' FETCH FIRST '. $limit .' ROWS ONLY'; return $query . ' FETCH FIRST '. (int)$limit .' ROWS ONLY';
} else { } else {
$sqlPieces = explode('from', $query); $sqlPieces = explode('from', $query);
$select = $sqlPieces[0]; $select = $sqlPieces[0];
Expand All @@ -56,8 +56,8 @@ public function modifyLimitQuery($query, $limit = false, $offset = false, $isMan


$sql = 'WITH OFFSET AS(' . $select . ', ROW_NUMBER() ' . $sql = 'WITH OFFSET AS(' . $select . ', ROW_NUMBER() ' .
'OVER(ORDER BY ' . $col[1] . ') AS doctrine_rownum FROM ' . $table . ')' . 'OVER(ORDER BY ' . $col[1] . ') AS doctrine_rownum FROM ' . $table . ')' .
$select . 'FROM OFFSET WHERE doctrine_rownum BETWEEN ' . $offset . $select . 'FROM OFFSET WHERE doctrine_rownum BETWEEN ' . (int)$offset .
'AND ' . ($offset + $limit - 1); 'AND ' . ((int)$offset + (int)$limit - 1);
return $sql; return $sql;
} }
} }
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/Connection/Pgsql.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ public function modifyLimitQuery($query, $limit = false, $offset = false, $isMan
$from = $match[2]; $from = $match[2];
$where = $match[3]; $where = $match[3];
$query = $manip . ' ' . $from . ' WHERE ctid=(SELECT ctid FROM ' $query = $manip . ' ' . $from . ' WHERE ctid=(SELECT ctid FROM '
. $from . ' ' . $where . ' LIMIT ' . $limit . ')'; . $from . ' ' . $where . ' LIMIT ' . (int)$limit . ')';


} else { } else {
if ( ! empty($limit)) { if ( ! empty($limit)) {
$query .= ' LIMIT ' . $limit; $query .= ' LIMIT ' . (int)$limit;
} }
if ( ! empty($offset)) { if ( ! empty($offset)) {
$query .= ' OFFSET ' . $offset; $query .= ' OFFSET ' . (int)$offset;
} }
} }
} }
Expand Down

0 comments on commit fcaa632

Please sign in to comment.