Repository navigation
Closed
Description
Our codebase contains currently gems such as:
$ids = array();
$parents = array($item['id']);
while (!empty($parents)) {
$parents = "'".implode("','", $parents)."'";
$query = \OC_DB::prepare('SELECT `id`, `permissions` FROM `*PREFIX*share`'
.' WHERE `parent` IN ('.$parents.')');
$result = $query->execute();
// Reset parents array, only go through loop again if
// items are found that need permissions removed
$parents = array();
while ($item = $result->fetchRow()) {
// Check if permissions need to be removed
if ($item['permissions'] & ~$permissions) {
// Add to list of items that need permissions removed
$ids[] = $item['id'];
$parents[] = $item['id'];
}
}
}
// Remove the permissions for all reshares of this item
if (!empty($ids)) {
$ids = "'".implode("','", $ids)."'";
// TODO this should be done with Doctrine platform objects
if (\OC_Config::getValue( "dbtype") === 'oci') {
$andOp = 'BITAND(`permissions`, ?)';
} else {
$andOp = '`permissions` & ?';
}
$query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `permissions` = '.$andOp
.' WHERE `id` IN ('.$ids.')');
$query->execute(array($permissions));Those cases are a potentially pitfall for SQL injections when the code is "incorrectly" called and is very hard to audit. This should use a helper for IN statements instead.
Activity
PVince81 commentedon Nov 24, 2014
Can we use this: https://github.com/doctrine/dbal/blob/master/docs/en/reference/data-retrieval-and-manipulation.rst#list-of-parameters-conversion ?
It seems when having arrays we cannot use prepared statements anyway... unless they have the same number of parameters every time.
PVince81 commentedon Nov 24, 2014
And maybe it could still use a prepared statement when only a single value was passed, in case that happens often.
PVince81 commentedon Dec 9, 2014
This will also need to support chunking (no more than 1000 elements in the
IN) statementDeepDiver1975 commentedon Jan 6, 2015
Can doctrine's query builder help us with this? Any way -> OC8.1
LukasReschke commentedon Feb 18, 2015
The query builder does this nicely from what I can tell.