This prevents discrepencies between the VM creation interface and LibvirtTool's validation of VM names.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/bin/LibvirtTool.pl | 23 +++++++++++++---------- testbot/lib/WineTestBot/VMs.pm | 17 +++++++++++++++++ 2 files changed, 30 insertions(+), 10 deletions(-)
diff --git a/testbot/bin/LibvirtTool.pl b/testbot/bin/LibvirtTool.pl index bc45533d2..e5dc8372e 100755 --- a/testbot/bin/LibvirtTool.pl +++ b/testbot/bin/LibvirtTool.pl @@ -118,20 +118,23 @@ if (!defined $Usage) Error "you must specify the VM name\n"; $Usage = 2; } - elsif ($VMKey =~ /^([a-zA-Z0-9_]+)$/) + else { - $VMKey = $1; # untaint - $VM = CreateVMs()->GetItem($VMKey); - if (!defined $VM) + $VMKey = WineTestBot::VM::UntaintName($VMKey); + if (!defined $VMKey) { - Error "VM $VMKey does not exist\n"; + Error "'$VMKey' is not a valid VM name\n"; $Usage = 2; } - } - else - { - Error "'$VMKey' is not a valid VM name\n"; - $Usage = 2; + else + { + $VM = CreateVMs()->GetItem($VMKey); + if (!defined $VM) + { + Error "VM $VMKey does not exist\n"; + $Usage = 2; + } + } } } if (defined $Usage) diff --git a/testbot/lib/WineTestBot/VMs.pm b/testbot/lib/WineTestBot/VMs.pm index 279b7bccd..2f4b70362 100644 --- a/testbot/lib/WineTestBot/VMs.pm +++ b/testbot/lib/WineTestBot/VMs.pm @@ -320,10 +320,27 @@ my $_SupportedMissions = { "wine" => { "win32" => 1, "wow32" => 1, "wow64" => 1 }, };
+sub UntaintName($) +{ + my ($VMName) = @_; + + return undef if (!defined $VMName); + $VMName =~ /^([a-zA-Z0-9_]+)$/; + return $1; +} + sub Validate($) { my ($self) = @_;
+ if (!defined $self->Name) + { + return ("Name", "The name must be set"); + } + if (!defined UntaintName($self->Name)) + { + return ("Name", "The name '". $self->Name ."' contains invalid characters"); + } if ($self->Type !~ /^(?:win32|win64|wine)$/ and $self->Role =~ /^(?:extra|winetest)$/) {