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 4fcaf3e7b7
commit 85565af560

View File

@ -324,6 +324,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
@ -491,6 +494,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
@ -498,6 +504,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)