From ae34d0ef86ac7acb1464339b4a0717bdfd2b0b4e Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Thu, 1 Aug 2024 20:29:40 +0300 Subject: [PATCH] Fix to unquote database name in view https://github.com/virtualmin/virtualmin-gpl/issues/723#issuecomment-2262824643 --- mysql/list_dbs.cgi | 5 +++-- mysql/mysql-lib.pl | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/mysql/list_dbs.cgi b/mysql/list_dbs.cgi index 1d0436190..02effc4d7 100755 --- a/mysql/list_dbs.cgi +++ b/mysql/list_dbs.cgi @@ -27,8 +27,9 @@ if (@{$d->{'data'}}) { next if ($access{'perms'} == 2 && !&can_edit_db($u->[1])); local @cols; push(@cols, "". - ($u->[1] eq '%' || $u->[1] eq '' ? $text{'dbs_any'} - : &html_escape($u->[1])).""); + ($u->[1] eq '%' || $u->[1] eq '' ? $text{'dbs_any'} : + &html_escape(&unquote_mysql_database( + $u->[1]))).""); push(@cols, $u->[2] eq '' ? $text{'dbs_anon'} : &html_escape($u->[2])); push(@cols, $u->[0] eq '%' ? $text{'dbs_any'} : diff --git a/mysql/mysql-lib.pl b/mysql/mysql-lib.pl index 3fef6874f..87b1fa69a 100755 --- a/mysql/mysql-lib.pl +++ b/mysql/mysql-lib.pl @@ -675,6 +675,15 @@ $db =~ s/%/\\%/g; return $db; } +# unquote_mysql_database(name) +# Returns a MySQL database name with \% and \_ characters unescaped +sub unquote_mysql_database { + my ($db) = @_; + $db =~ s/\\%/%/g; + $db =~ s/\\_/_/g; + return $db; +} + # escapestr(string) # Returns a string with quotes escaped, for use in SQL sub escapestr