Adding checks to force limit to always be a positive integer. Fixes potential out of bounds type queries with paginate(). Fixes #418

This commit is contained in:
Mark Story 2010-03-10 21:46:28 -05:00
parent d8a757ce75
commit 4c668c036c
2 changed files with 14 additions and 1 deletions

View file

@ -1168,8 +1168,13 @@ class Controller extends Object {
$type = $defaults[0];
unset($defaults[0]);
}
$options = array_merge(array('page' => 1, 'limit' => 20), $defaults, $options);
$options['limit'] = (empty($options['limit']) || !is_numeric($options['limit'])) ? 1 : $options['limit'];
$options['limit'] = (int) $options['limit'];
if (empty($options['limit']) || $options['limit'] < 1) {
$options['limit'] = 1;
}
extract($options);
if (is_array($scope) && !empty($scope)) {

View file

@ -595,6 +595,14 @@ class ControllerTest extends CakeTestCase {
$this->assertIdentical($Controller->params['paging']['ControllerPost']['pageCount'], 3);
$this->assertIdentical($Controller->params['paging']['ControllerPost']['prevPage'], false);
$this->assertIdentical($Controller->params['paging']['ControllerPost']['nextPage'], true);
$Controller->passedArgs = array();
$Controller->paginate = array('limit' => '-1');
$Controller->paginate('ControllerPost');
$this->assertIdentical($Controller->params['paging']['ControllerPost']['page'], 1);
$this->assertIdentical($Controller->params['paging']['ControllerPost']['pageCount'], 3);
$this->assertIdentical($Controller->params['paging']['ControllerPost']['prevPage'], false);
$this->assertIdentical($Controller->params['paging']['ControllerPost']['nextPage'], true);
}
/**