From b65452bda3cadf53b2a262df3eb43adea88d2401 Mon Sep 17 00:00:00 2001 From: Nikolai Merinov Date: Tue, 4 Feb 2025 09:13:46 +0200 Subject: bitbake: parse: Forbid ambiguous assignments to ${.}, ${+}, and ${:} variables Old code that parse variable names in assignment commands behave differently for variables that ends with special symbol for single-character variable names and multi-character variable names. For example: A+="1" # Change variable ${A}, '+' glued to '=' A+ = "1" # Change variable ${A+} +="1" # Change variable ${+}, the '+' symbol not part of assignment operator + = "1" # Change variable ${+} New code would always assume that '.=', '+=', and ':=' is assignment operator. As result code like the following would raise parsing error +="value" While code with extra spaces would work as before + = "value" # Change variable ${+} This change allow to catch issues in code that generate bitbake configuration files in a manner like "echo ${VARNAME}+=${VALUE} >> conf/local.conf" (Bitbake rev: 93059aad13a12cd69d86368795c88e5349197d5d) Signed-off-by: Nikolai Merinov Signed-off-by: Richard Purdie --- bitbake/lib/bb/parse/parse_py/ConfHandler.py | 4 +++- bitbake/lib/bb/tests/parse.py | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'bitbake/lib/bb') diff --git a/bitbake/lib/bb/parse/parse_py/ConfHandler.py b/bitbake/lib/bb/parse/parse_py/ConfHandler.py index 24f81f7e9e..1bde597254 100644 --- a/bitbake/lib/bb/parse/parse_py/ConfHandler.py +++ b/bitbake/lib/bb/parse/parse_py/ConfHandler.py @@ -20,7 +20,7 @@ from bb.parse import ParseError, resolve_file, ast, logger, handle __config_regexp__ = re.compile( r""" ^ (?Pexport\s+)? - (?P[a-zA-Z0-9\-_+.${}/~:]+?) + (?P[a-zA-Z0-9\-_+.${}/~:]*?) (\[(?P[a-zA-Z0-9\-_+.][a-zA-Z0-9\-_+.@/]*)\])? \s* ( @@ -166,6 +166,8 @@ def feeder(lineno, s, fn, statements, baseconfig=False, conffile=True): m = __config_regexp__.match(s) if m: groupd = m.groupdict() + if groupd['var'] == "": + raise ParseError("Empty variable name in assignment: '%s'" % s, fn, lineno); ast.handleData(statements, fn, lineno, groupd) return diff --git a/bitbake/lib/bb/tests/parse.py b/bitbake/lib/bb/tests/parse.py index cb60af3641..e3cba67ad4 100644 --- a/bitbake/lib/bb/tests/parse.py +++ b/bitbake/lib/bb/tests/parse.py @@ -443,3 +443,23 @@ include \\ in_file.write("\n".join(lines)) in_file.flush() bb.parse.handle(recipename_closed, bb.data.createCopy(self.d)) + + special_character_assignment = """ +A+="a" +A+ = "b" ++ = "c" +""" + ambigous_assignment = """ ++= "d" +""" + def test_parse_special_character_assignment(self): + f = self.parsehelper(self.special_character_assignment) + d = bb.parse.handle(f.name, self.d)[''] + self.assertEqual(d.getVar("A"), " a") + self.assertEqual(d.getVar("A+"), "b") + self.assertEqual(d.getVar("+"), "c") + + f = self.parsehelper(self.ambigous_assignment) + with self.assertRaises(bb.parse.ParseError) as error: + bb.parse.handle(f.name, self.d) + self.assertIn("Empty variable name in assignment", str(error.exception)) -- cgit v1.2.3-54-g00ecf