From 9daa888f0fd16cde0b9b22c375f2310678474039 Mon Sep 17 00:00:00 2001 From: Caleb Connolly Date: Sun, 23 Jun 2024 21:07:24 +0200 Subject: [PATCH] core: chroot: validate name for rootfs chroot (MR 2332) Make sure we get a valid name in the rootfs type chroot. Signed-off-by: Caleb Connolly --- pmb/core/chroot.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pmb/core/chroot.py b/pmb/core/chroot.py index 216ecc01..e370bdd2 100644 --- a/pmb/core/chroot.py +++ b/pmb/core/chroot.py @@ -70,6 +70,10 @@ class Chroot: if self.__type == ChrootType.IMAGE and not Path(self.__name).exists(): raise ValueError(f"Image file '{self.__name}' does not exist") + # rootfs suffixes must have a valid device name + if self.__type == ChrootType.ROOTFS and (len(self.__name) < 3 or "-" not in self.__name): + raise ValueError(f"Invalid device name: '{self.__name}'") + def __str__(self) -> str: if len(self.__name) > 0 and self.type != ChrootType.IMAGE: return f"{self.__type.value}_{self.__name}"