Skip to content

Commit

Permalink
Merge #16004 - Fix #15898 - escape tbl_storage_engine argument
Browse files Browse the repository at this point in the history
Pull-request: #16004
Fixes: #15898
Security: ca42395
Ref: #16004
Ref: #15898
For now I do not have a CVE code for this one.
Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed Mar 19, 2020
2 parents abcf875 + f6af795 commit e1f5dfc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion libraries/classes/CreateAddField.php
Expand Up @@ -467,7 +467,7 @@ public function getTableCreationQuery(string $db, string $table): string
if (! empty($_POST['tbl_storage_engine'])
&& ($_POST['tbl_storage_engine'] != 'Default')
) {
$sqlQuery .= ' ENGINE = ' . $_POST['tbl_storage_engine'];
$sqlQuery .= ' ENGINE = ' . $this->dbi->escapeString($_POST['tbl_storage_engine']);
}
if (! empty($_POST['tbl_collation'])) {
$sqlQuery .= Util::getCharsetQueryPart($_POST['tbl_collation']);
Expand Down
17 changes: 17 additions & 0 deletions test/classes/CreateAddFieldTest.php
Expand Up @@ -114,6 +114,23 @@ public function providerGetTableCreationQuery()
'spatial_indexes' => '{}',
],
],
[
'CREATE TABLE `db`.`table` () ENGINE = Inno\\\'DB CHARSET=armscii8 COMMENT = \'my \\\'table\';',
'db',
'table',
[
'field_name' => [],
'primary_indexes' => '{}',
'indexes' => '{}',
'unique_indexes' => '{}',
'fulltext_indexes' => '{}',
'spatial_indexes' => '{}',
'tbl_storage_engine' => 'Inno\'DB',
'tbl_collation' => 'armscii8',
'connection' => 'aaaa',
'comment' => 'my \'table',
],
],
];
}

Expand Down
4 changes: 4 additions & 0 deletions test/classes/Dbi/DbiDummyTest.php
Expand Up @@ -147,5 +147,9 @@ public function testEscapeString(): void
'a',
$GLOBALS['dbi']->escapeString('a')
);
$this->assertEquals(
'a\\\'',
$GLOBALS['dbi']->escapeString('a\'')
);
}
}
2 changes: 1 addition & 1 deletion test/classes/Stubs/DbiDummy.php
Expand Up @@ -434,7 +434,7 @@ public function fieldFlags($result, $i)
*/
public function escapeString($link, $str)
{
return $str;
return addslashes($str);
}

/**
Expand Down

0 comments on commit e1f5dfc

Please sign in to comment.