Skip to content

Commit

Permalink
Merge pull request #26340 from owncloud/stable9.1-36d6f3ba8b7b7db8f4d…
Browse files Browse the repository at this point in the history
…8b2a70504fd184a30cc50

[stable9.1] Escape special characters
  • Loading branch information
Vincent Petry committed Oct 11, 2016
2 parents 713d04a + 522e714 commit dc00515
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion apps/dav/lib/Connector/Sabre/CustomPropertiesBackend.php
Expand Up @@ -327,7 +327,7 @@ private function loadChildrenProperties(Directory $node, $requestedProperties) {

$result = $this->connection->executeQuery(
$sql,
array($this->user, rtrim($path, '/') . '/%', $requestedProperties),
array($this->user, $this->connection->escapeLikeParameter(rtrim($path, '/')) . '/%', $requestedProperties),
array(null, null, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY)
);

Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/Access.php
Expand Up @@ -623,7 +623,7 @@ private function _createAltInternalOwnCloudNameForUsers($name) {
* "Developers"
*/
private function _createAltInternalOwnCloudNameForGroups($name) {
$usedNames = $this->groupMapper->getNamesBySearch($name.'_%');
$usedNames = $this->groupMapper->getNamesBySearch($name, "", '_%');
if(!($usedNames) || count($usedNames) === 0) {
$lastNo = 1; //will become name_2
} else {
Expand Down
6 changes: 4 additions & 2 deletions apps/user_ldap/lib/Mapping/AbstractMapping.php
Expand Up @@ -138,16 +138,18 @@ public function getNameByDN($fdn) {
/**
* Searches mapped names by the giving string in the name column
* @param string $search
* @param string $prefixMatch
* @param string $postfixMatch
* @return string[]
*/
public function getNamesBySearch($search) {
public function getNamesBySearch($search, $prefixMatch = "", $postfixMatch = "") {
$query = $this->dbc->prepare('
SELECT `owncloud_name`
FROM `'. $this->getTableName() .'`
WHERE `owncloud_name` LIKE ?
');

$res = $query->execute(array($search));
$res = $query->execute(array($prefixMatch.$this->dbc->escapeLikeParameter($search).$postfixMatch));
$names = array();
if($res !== false) {
while($row = $query->fetch()) {
Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/tests/Mapping/AbstractMappingTest.php
Expand Up @@ -164,7 +164,7 @@ public function testGetMethods() {
public function testSearch() {
list($mapper,) = $this->initTest();

$names = $mapper->getNamesBySearch('%oo%');
$names = $mapper->getNamesBySearch('oo', '%', '%');
$this->assertTrue(is_array($names));
$this->assertSame(2, count($names));
$this->assertTrue(in_array('Foobar', $names));
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Group/Database.php
Expand Up @@ -285,7 +285,7 @@ public function usersInGroup($gid, $search = '', $limit = null, $offset = null)
$parameters = [$gid];
$searchLike = '';
if ($search !== '') {
$parameters[] = '%' . $search . '%';
$parameters[] = '%' . $this->dbConn->escapeLikeParameter($search) . '%';
$searchLike = ' AND `uid` LIKE ?';
}

Expand All @@ -311,7 +311,7 @@ public function countUsersInGroup($gid, $search = '') {
$parameters = [$gid];
$searchLike = '';
if ($search !== '') {
$parameters[] = '%' . $search . '%';
$parameters[] = '%' . $this->dbConn->escapeLikeParameter($search) . '%';
$searchLike = ' AND `uid` LIKE ?';
}

Expand Down
2 changes: 1 addition & 1 deletion lib/private/Repair/RepairLegacyStorages.php
Expand Up @@ -172,7 +172,7 @@ public function run(IOutput $out) {
$sql = 'SELECT `id`, `numeric_id` FROM `*PREFIX*storages`'
. ' WHERE `id` LIKE ?'
. ' ORDER BY `id`';
$result = $this->connection->executeQuery($sql, array($dataDirId . '%'));
$result = $this->connection->executeQuery($sql, array($this->connection->escapeLikeParameter($dataDirId) . '%'));

while ($row = $result->fetch()) {
$currentId = $row['id'];
Expand Down

0 comments on commit dc00515

Please sign in to comment.