From c2e6a0048dc6174acd5ae0ab7f7834eae6d6dc40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kl=C3=B6tzke?= Date: Sun, 3 Nov 2024 21:26:57 +0100 Subject: [PATCH] input: tighten layer name rules Internally, the empty string is used for the main recipes. Allowing path separators in the layer name will probably also blow up. Rule out both. Some of the type checks were also missing. Make sure that the layer name is a string and that a layers entry is a dict if not already a string. --- pym/bob/input.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pym/bob/input.py b/pym/bob/input.py index 61b23340..4c83d427 100644 --- a/pym/bob/input.py +++ b/pym/bob/input.py @@ -1739,13 +1739,28 @@ def getScm(self): return self.__scm class LayerValidator: + @staticmethod + def __validateName(name): + if name == "": + raise schema.SchemaError("Layer name must not be empty") + if any((c in name) for c in '\\/'): + raise schema.SchemaError("Invalid character in layer name") + def validate(self, data): - if isinstance(data,str): + if isinstance(data, str): + self.__validateName(data) return LayerSpec(data) + elif not isinstance(data, dict): + raise schema.SchemaUnexpectedTypeError("Layer entry must be a string or a dict", None) + if 'name' not in data: raise schema.SchemaMissingKeyError("Missing 'name' key in {}".format(data), None) + elif not isinstance(data['name'], str): + raise schema.SchemaUnexpectedTypeError("Layer name must be a string", None) + _data = data.copy(); name = _data.get('name') + self.__validateName(name) del _data['name'] return LayerSpec(name, RecipeSet.LAYERS_SCM_SCHEMA.validate(_data)[0])