Skip to content

Commit

Permalink
Use sprintf('%d') like in DB2, SQLServer and Oracle to harden against…
Browse files Browse the repository at this point in the history
… wrong limit and offset

Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Nov 19, 2021
1 parent 821b4f0 commit 9e6d5c5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -3384,11 +3384,11 @@ final public function modifyLimitQuery($query, $limit, $offset = 0)
protected function doModifyLimitQuery($query, $limit, $offset)
{
if ($limit !== null) {
$query .= ' LIMIT ' . $limit;
$query .= sprintf(' LIMIT %d', $limit);
}

if ($offset > 0) {
$query .= ' OFFSET ' . $offset;
$query .= sprintf(' OFFSET %d', $offset);
}

return $query;
Expand Down
6 changes: 3 additions & 3 deletions src/Platforms/MySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ class MySQLPlatform extends AbstractPlatform
protected function doModifyLimitQuery($query, $limit, $offset)
{
if ($limit !== null) {
$query .= ' LIMIT ' . $limit;
$query .= sprintf(' LIMIT %d', $limit);

if ($offset > 0) {
$query .= ' OFFSET ' . $offset;
$query .= sprintf(' OFFSET %d', $offset);
}
} elseif ($offset > 0) {
// 2^64-1 is the maximum of unsigned BIGINT, the biggest limit possible
$query .= ' LIMIT 18446744073709551615 OFFSET ' . $offset;
$query .= sprintf(' LIMIT 18446744073709551615 OFFSET %d', $offset);
}

return $query;
Expand Down
2 changes: 1 addition & 1 deletion src/Platforms/SqlitePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff)
protected function doModifyLimitQuery($query, $limit, $offset)
{
if ($limit === null && $offset > 0) {
return $query . ' LIMIT -1 OFFSET ' . $offset;
return $query . sprintf(' LIMIT -1 OFFSET %d', $offset);
}

return parent::doModifyLimitQuery($query, $limit, $offset);
Expand Down

0 comments on commit 9e6d5c5

Please sign in to comment.