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

Commit fcaa632

Browse files
committed
[Security] Fix sql injection in modifyLimitQuery() for PgSQL and DB2
1 parent 728e669 commit fcaa632

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/Doctrine/Connection/Db2.php

Lines changed: 3 additions & 3 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function modifyLimitQuery($query, $limit = false, $offset = false, $isMan
46
return $query;
46
return $query;
47

47

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

56

57
$sql = 'WITH OFFSET AS(' . $select . ', ROW_NUMBER() ' .
57
$sql = 'WITH OFFSET AS(' . $select . ', ROW_NUMBER() ' .
58
'OVER(ORDER BY ' . $col[1] . ') AS doctrine_rownum FROM ' . $table . ')' .
58
'OVER(ORDER BY ' . $col[1] . ') AS doctrine_rownum FROM ' . $table . ')' .
59-
$select . 'FROM OFFSET WHERE doctrine_rownum BETWEEN ' . $offset .
59+
$select . 'FROM OFFSET WHERE doctrine_rownum BETWEEN ' . (int)$offset .
60-
'AND ' . ($offset + $limit - 1);
60+
'AND ' . ((int)$offset + (int)$limit - 1);
61
return $sql;
61
return $sql;
62
}
62
}
63
}
63
}

lib/Doctrine/Connection/Pgsql.php

Lines changed: 3 additions & 3 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -142,14 +142,14 @@ public function modifyLimitQuery($query, $limit = false, $offset = false, $isMan
142
$from = $match[2];
142
$from = $match[2];
143
$where = $match[3];
143
$where = $match[3];
144
$query = $manip . ' ' . $from . ' WHERE ctid=(SELECT ctid FROM '
144
$query = $manip . ' ' . $from . ' WHERE ctid=(SELECT ctid FROM '
145-
. $from . ' ' . $where . ' LIMIT ' . $limit . ')';
145+
. $from . ' ' . $where . ' LIMIT ' . (int)$limit . ')';
146

146

147
} else {
147
} else {
148
if ( ! empty($limit)) {
148
if ( ! empty($limit)) {
149-
$query .= ' LIMIT ' . $limit;
149+
$query .= ' LIMIT ' . (int)$limit;
150
}
150
}
151
if ( ! empty($offset)) {
151
if ( ! empty($offset)) {
152-
$query .= ' OFFSET ' . $offset;
152+
$query .= ' OFFSET ' . (int)$offset;
153
}
153
}
154
}
154
}
155
}
155
}

0 commit comments

Comments
 (0)