Skip to content

Commit

Permalink
Properly escape generated XML export
Browse files Browse the repository at this point in the history
Many fields could contain XML markup, so we need to ensure the generated
XML is valid.

Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Jun 30, 2016
1 parent bd2080c commit 7de139b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions libraries/plugins/export/ExportXml.php
Expand Up @@ -185,7 +185,7 @@ private function _exportDefinitions($db, $type, $dbitype, $names)
if ($names) {
foreach ($names as $name) {
$head .= ' <pma:' . $type . ' name="'
. $name . '">' . $crlf;
. htmlspecialchars($name) . '">' . $crlf;

// Do some formatting
$sql = $GLOBALS['dbi']->getDefinition($db, $dbitype, $name);
Expand Down Expand Up @@ -232,7 +232,7 @@ public function exportHeader()
. '- version ' . PMA_VERSION . $crlf
. '- https://www.phpmyadmin.net' . $crlf
. '-' . $crlf
. '- ' . __('Host:') . ' ' . $cfg['Server']['host'];
. '- ' . __('Host:') . ' ' . htmlspecialchars($cfg['Server']['host']);
if (!empty($cfg['Server']['port'])) {
$head .= ':' . $cfg['Server']['port'];
}
Expand Down Expand Up @@ -263,7 +263,7 @@ public function exportHeader()
$head .= ' -->' . $crlf;
$head .= ' <pma:structure_schemas>' . $crlf;
$head .= ' <pma:database name="' . htmlspecialchars($db)
. '" collation="' . $db_collation . '" charset="' . $db_charset
. '" collation="' . htmlspecialchars($db_collation) . '" charset="' . htmlspecialchars($db_charset)
. '">' . $crlf;

if (count($tables) == 0) {
Expand Down Expand Up @@ -296,7 +296,7 @@ public function exportHeader()
continue;
}

$head .= ' <pma:' . $type . ' name="' . $table . '">'
$head .= ' <pma:' . $type . ' name="' . htmlspecialchars($table) . '">'
. $crlf;

$tbl = " " . htmlspecialchars($tbl);
Expand All @@ -314,7 +314,7 @@ public function exportHeader()
foreach ($triggers as $trigger) {
$code = $trigger['create'];
$head .= ' <pma:trigger name="'
. $trigger['name'] . '">' . $crlf;
. htmlspecialchars($trigger['name']) . '">' . $crlf;

// Do some formatting
$code = mb_substr(rtrim($code), 0, -3);
Expand Down Expand Up @@ -402,7 +402,7 @@ public function exportDBHeader($db, $db_alias = '')
) {
$head = ' <!--' . $crlf
. ' - ' . __('Database:') . ' ' . '\''
. $db_alias . '\'' . $crlf
. htmlspecialchars($db_alias) . '\'' . $crlf
. ' -->' . $crlf . ' <database name="'
. htmlspecialchars($db_alias) . '">' . $crlf;

Expand Down Expand Up @@ -491,7 +491,7 @@ public function exportData(
unset($i);

$buffer = ' <!-- ' . __('Table') . ' '
. $table_alias . ' -->' . $crlf;
. htmlspecialchars($table_alias) . ' -->' . $crlf;
if (!PMA_exportOutputHandler($buffer)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion test/classes/plugin/export/ExportXmlTest.php
Expand Up @@ -589,7 +589,7 @@ public function testExportData()
$result = ob_get_clean();

$this->assertContains(
"<!-- Table ta<ble -->",
"<!-- Table ta&lt;ble -->",
$result
);

Expand Down

0 comments on commit 7de139b

Please sign in to comment.