Francois Gouget : testbot: Validate VM names and add UntaintName().

Alexandre Julliard julliard at winehq.org
Mon Dec 2 13:24:48 CST 2019


Module: tools
Branch: master
Commit: 4bb065f0b60710ae3c91d3444bf1df1febd39023
URL:    https://source.winehq.org/git/tools.git/?a=commit;h=4bb065f0b60710ae3c91d3444bf1df1febd39023

Author: Francois Gouget <fgouget at codeweavers.com>
Date:   Mon Dec  2 13:55:07 2019 +0100

testbot: Validate VM names and add UntaintName().

This prevents discrepencies between the VM creation interface and
LibvirtTool's validation of VM names.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 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 faac0b3..a2939e7 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 279b7bc..2f4b703 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)$/)
   {




More information about the wine-cvs mailing list