dom0/core: verify VM name for not-allowed characters (#656)

This commit is contained in:
Marek Marczykowski 2012-08-23 02:50:18 +02:00
parent dde1b5b2f5
commit 536eb00b9c

View File

@ -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)