From 536eb00b9c24ad115d52a49e63af637112381af4 Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Thu, 23 Aug 2012 02:50:18 +0200 Subject: [PATCH] dom0/core: verify VM name for not-allowed characters (#656) --- dom0/qvm-core/qubes.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/dom0/qvm-core/qubes.py b/dom0/qvm-core/qubes.py index 26cd3972..f52b5fca 100755 --- a/dom0/qvm-core/qubes.py +++ b/dom0/qvm-core/qubes.py @@ -315,6 +315,9 @@ class QubesVm(object): assert self.__qid < qubes_max_qid, "VM id out of bounds!" assert self.name is not None + if not self.verify_name(self.name): + raise QubesException("Invalid characters in VM name") + if self.netvm is not None: self.netvm.connected_vms[self.qid] = self @@ -482,6 +485,9 @@ class QubesVm(object): else: return False + def verify_name(self, name): + return re.match(r"^[a-zA-Z0-9-]*$", name) is not None + def pre_rename(self, new_name): pass @@ -489,6 +495,9 @@ class QubesVm(object): if self.is_running(): raise QubesException("Cannot change name of running VM!") + if not self.verify_name(name): + raise QubesException("Invalid characters in VM name") + self.pre_rename(name) new_conf = "%s/%s.conf" % (self.dir_path, name)