From 6d0f28b425dc9f975543301c4b194dd6fbdd494d Mon Sep 17 00:00:00 2001 From: Piotr Przybylski Date: Wed, 13 Jul 2011 23:40:58 +0200 Subject: [PATCH 1/7] Improve readability of XML export code --- libraries/export/xml.php | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/libraries/export/xml.php b/libraries/export/xml.php index 9bafb0998d..9fd2a0202a 100644 --- a/libraries/export/xml.php +++ b/libraries/export/xml.php @@ -82,13 +82,12 @@ function PMA_exportFooter() { function PMA_exportHeader() { global $crlf; global $cfg; - global $what; global $db; global $table; global $tables; - $export_struct = isset($GLOBALS[$what . '_export_struc']) ? true : false; - $export_data = isset($GLOBALS[$what . '_export_contents']) ? true : false; + $export_struct = isset($GLOBALS['xml_export_struc']) ? true : false; + $export_data = isset($GLOBALS['xml_export_contents']) ? true : false; if ($GLOBALS['output_charset_conversion']) { $charset = $GLOBALS['charset_of_file']; @@ -142,11 +141,11 @@ function PMA_exportHeader() { $type = 'table'; } - if ($is_view && ! isset($GLOBALS[$what . '_export_views'])) { + if ($is_view && ! isset($GLOBALS['xml_export_views'])) { continue; } - if (! $is_view && ! isset($GLOBALS[$what . '_export_tables'])) { + if (! $is_view && ! isset($GLOBALS['xml_export_tables'])) { continue; } @@ -158,7 +157,7 @@ function PMA_exportHeader() { $head .= $tbl . ';' . $crlf; $head .= ' ' . $crlf; - if (isset($GLOBALS[$what . '_export_triggers']) && $GLOBALS[$what . '_export_triggers']) { + if (isset($GLOBALS['xml_export_triggers']) && $GLOBALS['xml_export_triggers']) { // Export triggers $triggers = PMA_DBI_get_triggers($db, $table); if ($triggers) { @@ -181,7 +180,7 @@ function PMA_exportHeader() { } } - if (isset($GLOBALS[$what . '_export_functions']) && $GLOBALS[$what . '_export_functions']) { + if (isset($GLOBALS['xml_export_functions']) && $GLOBALS['xml_export_functions']) { // Export functions $functions = PMA_DBI_get_procedures_or_functions($db, 'FUNCTION'); if ($functions) { @@ -204,7 +203,7 @@ function PMA_exportHeader() { } } - if (isset($GLOBALS[$what . '_export_procedures']) && $GLOBALS[$what . '_export_procedures']) { + if (isset($GLOBALS['xml_export_procedures']) && $GLOBALS['xml_export_procedures']) { // Export procedures $procedures = PMA_DBI_get_procedures_or_functions($db, 'PROCEDURE'); if ($procedures) { @@ -251,9 +250,8 @@ function PMA_exportHeader() { */ function PMA_exportDBHeader($db) { global $crlf; - global $what; - if (isset($GLOBALS[$what . '_export_contents']) && $GLOBALS[$what . '_export_contents']) { + if (isset($GLOBALS['xml_export_contents']) && $GLOBALS['xml_export_contents']) { $head = ' ' . $crlf @@ -278,9 +276,8 @@ function PMA_exportDBHeader($db) { */ function PMA_exportDBFooter($db) { global $crlf; - global $what; - if (isset($GLOBALS[$what . '_export_contents']) && $GLOBALS[$what . '_export_contents']) { + if (isset($GLOBALS['xml_export_contents']) && $GLOBALS['xml_export_contents']) { return PMA_exportOutputHandler(' ' . $crlf); } else @@ -317,9 +314,8 @@ function PMA_exportDBCreate($db) { * @access public */ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { - global $what; - - if (isset($GLOBALS[$what . '_export_contents']) && $GLOBALS[$what . '_export_contents']) { + + if (isset($GLOBALS['xml_export_contents']) && $GLOBALS['xml_export_contents']) { $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); $columns_cnt = PMA_DBI_num_fields($result); From 65d962d39703b412dc482be47e092f97933eb8e0 Mon Sep 17 00:00:00 2001 From: Piotr Przybylski Date: Wed, 13 Jul 2011 23:42:29 +0200 Subject: [PATCH 2/7] Better escaping in XML export Note: it's still incorrect --- libraries/export/xml.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/export/xml.php b/libraries/export/xml.php index 9fd2a0202a..cc6fe957a8 100644 --- a/libraries/export/xml.php +++ b/libraries/export/xml.php @@ -122,7 +122,7 @@ function PMA_exportHeader() { $head .= ' - Structure schemas' . $crlf; $head .= ' -->' . $crlf; $head .= ' ' . $crlf; - $head .= ' ' . $crlf; + $head .= ' ' . $crlf; if (count($tables) == 0) { $tables[] = $table; @@ -319,6 +319,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); $columns_cnt = PMA_DBI_num_fields($result); + $columns = array(); for ($i = 0; $i < $columns_cnt; $i++) { $columns[$i] = stripslashes(str_replace(' ', '_', PMA_DBI_field_name($result, $i))); } @@ -336,7 +337,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { if (!isset($record[$i]) || is_null($record[$i])) { $record[$i] = 'NULL'; } - $buffer .= ' ' . htmlspecialchars((string)$record[$i]) + $buffer .= ' ' . htmlspecialchars((string)$record[$i]) . '' . $crlf; } $buffer .= ' ' . $crlf; From 70083ad58346ff7190bcd8e56b63ab92f6abfa40 Mon Sep 17 00:00:00 2001 From: Piotr Przybylski Date: Thu, 14 Jul 2011 00:05:58 +0200 Subject: [PATCH 3/7] Fix XML export so it actually can export table structure More escaping fixes --- libraries/export/xml.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libraries/export/xml.php b/libraries/export/xml.php index cc6fe957a8..83b51ee4c3 100644 --- a/libraries/export/xml.php +++ b/libraries/export/xml.php @@ -86,7 +86,9 @@ function PMA_exportHeader() { global $table; global $tables; - $export_struct = isset($GLOBALS['xml_export_struc']) ? true : false; + $export_struct = isset($GLOBALS['xml_export_functions']) || isset($GLOBALS['xml_export_procedures']) + || isset($GLOBALS['xml_export_tables']) || isset($GLOBALS['xml_export_triggers']) + || isset($GLOBALS['xml_export_views']); $export_data = isset($GLOBALS['xml_export_contents']) ? true : false; if ($GLOBALS['output_charset_conversion']) { @@ -151,7 +153,7 @@ function PMA_exportHeader() { $head .= ' ' . $crlf; - $tbl = " " . $tbl; + $tbl = " " . htmlspecialchars($tbl); $tbl = str_replace("\n", "\n ", $tbl); $head .= $tbl . ';' . $crlf; @@ -167,7 +169,7 @@ function PMA_exportHeader() { // Do some formatting $code = substr(rtrim($code), 0, -3); - $code = " " . $code; + $code = " " . htmlspecialchars($code); $code = str_replace("\n", "\n ", $code); $head .= $code . $crlf; @@ -190,7 +192,7 @@ function PMA_exportHeader() { // Do some formatting $sql = PMA_DBI_get_definition($db, 'FUNCTION', $function); $sql = rtrim($sql); - $sql = " " . $sql; + $sql = " " . htmlspecialchars($sql); $sql = str_replace("\n", "\n ", $sql); $head .= $sql . $crlf; @@ -213,7 +215,7 @@ function PMA_exportHeader() { // Do some formatting $sql = PMA_DBI_get_definition($db, 'PROCEDURE', $procedure); $sql = rtrim($sql); - $sql = " " . $sql; + $sql = " " . htmlspecialchars($sql); $sql = str_replace("\n", "\n ", $sql); $head .= $sql . $crlf; @@ -255,7 +257,7 @@ function PMA_exportDBHeader($db) { $head = ' ' . $crlf - . ' ' . $crlf; + . ' ' . $crlf; return PMA_exportOutputHandler($head); } From 2cc22c8aba33ad12b3d98905d6dfc29f7c878837 Mon Sep 17 00:00:00 2001 From: Piotr Przybylski Date: Thu, 14 Jul 2011 21:28:41 +0200 Subject: [PATCH 4/7] Fix CodeGen export --- libraries/export/codegen.php | 76 +++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 27 deletions(-) diff --git a/libraries/export/codegen.php b/libraries/export/codegen.php index 8e36f408f6..7160122e97 100644 --- a/libraries/export/codegen.php +++ b/libraries/export/codegen.php @@ -138,12 +138,12 @@ function PMA_exportDBCreate($db) */ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { - global $CG_FORMATS, $CG_HANDLERS; - $format = cgGetOption("format"); - $index = array_search($format, $CG_FORMATS); - if ($index >= 0) - return PMA_exportOutputHandler($CG_HANDLERS[$index]($db, $table, $crlf)); - return PMA_exportOutputHandler(sprintf("%s is not supported.", $format)); + global $CG_FORMATS, $CG_HANDLERS; + $format = cgGetOption("format"); + if (isset($CG_FORMATS[$format])) { + return PMA_exportOutputHandler($CG_HANDLERS[$format]($db, $table, $crlf)); + } + return PMA_exportOutputHandler(sprintf("%s is not supported.", $format)); } /** @@ -209,28 +209,50 @@ class TableProperty function getIndexName() { if (strlen($this->key)>0) - return "index=\"" . $this->name . "\""; + return "index=\"" . htmlspecialchars($this->name, ENT_COMPAT, 'UTF-8') . "\""; return ""; } function isPK() { return $this->key=="PRI"; } - function format($pattern) + function formatCs($text) + { + $text=str_replace("#name#", cgMakeIdentifier($this->name, false), $text); + return $this->format($text); + } + function formatXml($text) + { + $text=str_replace("#name#", htmlspecialchars($this->name, ENT_COMPAT, 'UTF-8'), $text); + $text=str_replace("#indexName#", $this->getIndexName(), $text); + return $this->format($text); + } + function format($text) { - $text=$pattern; - $text=str_replace("#name#", $this->name, $text); + $text=str_replace("#ucfirstName#", cgMakeIdentifier($this->name), $text); + $text=str_replace("#dotNetPrimitiveType#", $this->getDotNetPrimitiveType(), $text); + $text=str_replace("#dotNetObjectType#", $this->getDotNetObjectType(), $text); $text=str_replace("#type#", $this->getPureType(), $text); $text=str_replace("#notNull#", $this->isNotNull(), $text); $text=str_replace("#unique#", $this->isUnique(), $text); - $text=str_replace("#ucfirstName#", ucfirst($this->name), $text); - $text=str_replace("#dotNetPrimitiveType#", $this->getDotNetPrimitiveType(), $text); - $text=str_replace("#dotNetObjectType#", $this->getDotNetObjectType(), $text); - $text=str_replace("#indexName#", $this->getIndexName(), $text); return $text; } } + function cgMakeIdentifier($str, $ucfirst = true) + { + // remove unsafe characters + $str = preg_replace('/[^\p{L}\p{Nl}_]/u', '', $str); + // make sure first character is a letter or _ + if (!preg_match('/^\pL/u', $str)) { + $str = '_' . $str; + } + if ($ucfirst) { + $str = ucfirst($str); + } + return $str; + } + function handleNHibernateCSBody($db, $table, $crlf) { $lines=array(); @@ -244,31 +266,31 @@ class TableProperty $lines[] = "using System.Collections;"; $lines[] = "using System.Collections.Generic;"; $lines[] = "using System.Text;"; - $lines[] = "namespace ".ucfirst($db); + $lines[] = "namespace ".cgMakeIdentifier($db); $lines[] = "{"; - $lines[] = " #region ".ucfirst($table); - $lines[] = " public class ".ucfirst($table); + $lines[] = " #region ".cgMakeIdentifier($table); + $lines[] = " public class ".cgMakeIdentifier($table); $lines[] = " {"; $lines[] = " #region Member Variables"; foreach ($tableProperties as $tablePropertie) - $lines[] = $tablePropertie->format(" protected #dotNetPrimitiveType# _#name#;"); + $lines[] = $tablePropertie->formatCs(" protected #dotNetPrimitiveType# _#name#;"); $lines[] = " #endregion"; $lines[] = " #region Constructors"; - $lines[] = " public ".ucfirst($table)."() { }"; + $lines[] = " public ".cgMakeIdentifier($table)."() { }"; $temp = array(); foreach ($tableProperties as $tablePropertie) if (! $tablePropertie->isPK()) - $temp[] = $tablePropertie->format("#dotNetPrimitiveType# #name#"); - $lines[] = " public ".ucfirst($table)."(".implode(", ", $temp).")"; + $temp[] = $tablePropertie->formatCs("#dotNetPrimitiveType# #name#"); + $lines[] = " public ".cgMakeIdentifier($table)."(".implode(", ", $temp).")"; $lines[] = " {"; foreach ($tableProperties as $tablePropertie) if (! $tablePropertie->isPK()) - $lines[] = $tablePropertie->format(" this._#name#=#name#;"); + $lines[] = $tablePropertie->formatCs(" this._#name#=#name#;"); $lines[] = " }"; $lines[] = " #endregion"; $lines[] = " #region Public Properties"; foreach ($tableProperties as $tablePropertie) - $lines[] = $tablePropertie->format(" public virtual #dotNetPrimitiveType# _#ucfirstName#\n {\n get {return _#name#;}\n set {_#name#=value;}\n }"); + $lines[] = $tablePropertie->formatCs(" public virtual #dotNetPrimitiveType# #ucfirstName#\n {\n get {return _#name#;}\n set {_#name#=value;}\n }"); $lines[] = " #endregion"; $lines[] = " }"; $lines[] = " #endregion"; @@ -282,8 +304,8 @@ class TableProperty { $lines=array(); $lines[] = ""; - $lines[] = ""; - $lines[] = " "; + $lines[] = ""; + $lines[] = " "; $result = PMA_DBI_query(sprintf("DESC %s.%s", PMA_backquote($db), PMA_backquote($table))); if ($result) { @@ -293,9 +315,9 @@ class TableProperty foreach ($tableProperties as $tablePropertie) { if ($tablePropertie->isPK()) - $lines[] = $tablePropertie->format(" \n \n \n "); + $lines[] = $tablePropertie->formatXml(" \n \n \n "); else - $lines[] = $tablePropertie->format(" \n \n "); + $lines[] = $tablePropertie->formatXml(" \n \n "); } PMA_DBI_free_result($result); } From b185ca88f7c8241804cff13a2b315fc3d1222a38 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Fri, 15 Jul 2011 08:53:20 -0400 Subject: [PATCH 5/7] remove version number in /setup --- ChangeLog | 1 + setup/index.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 298b04348c..90e2b24c24 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,7 @@ phpMyAdmin - ChangeLog - bug #3350790 [interface] JS error in Table->Structure->Index->Edit - bug #3353811 [interface] Info message has "error" class - bug #3357837 [interface] TABbing through a NULL field in the inline mode resets NULL +- remove version number in /setup 3.4.3.1 (2011-07-02) - [security] Fixed possible session manipulation in swekey authentication, see PMASA-2011-5 diff --git a/setup/index.php b/setup/index.php index 0d4ae4ffaf..d202eae834 100644 --- a/setup/index.php +++ b/setup/index.php @@ -29,7 +29,7 @@ require './libraries/header_http.inc.php'; -phpMyAdmin <?php echo $GLOBALS['PMA_Config']->get('PMA_VERSION'); ?> setup +phpMyAdmin setup @@ -40,7 +40,7 @@ require './libraries/header_http.inc.php'; -

phpMyAdmin get('PMA_VERSION'); ?> setup

+

phpMyAdmin setup