From 0ac02c2d2771ad98f2f98c7d3bdcf58ed8577410 Mon Sep 17 00:00:00 2001 From: Maciej Kurc Date: Wed, 29 Jul 2020 16:33:18 +0200 Subject: [PATCH] Added a feature name check to mergedb.py Signed-off-by: Maciej Kurc --- utils/mergedb.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/utils/mergedb.py b/utils/mergedb.py index f3d477a3..4aa412ef 100755 --- a/utils/mergedb.py +++ b/utils/mergedb.py @@ -9,9 +9,39 @@ # # SPDX-License-Identifier: ISC -import os, sys +import os, sys, re from prjxray import util +TAG_PART_RE = re.compile(r"^[a-zA-Z][0-9a-zA-Z_]*(\[[0-9]+\])?$") + + +def check_tag_name(tag): + ''' + Checks if the tag name given by the used conforms to the valid fasm + name rules. + + >>> check_tag_name("CELL.feature19.ENABLED") + True + >>> check_tag_name("FEATURE") + True + >>> check_tag_name("TAG.") + False + >>> check_tag_name(".TAG") + False + >>> check_tag_name("CELL..FEATURE") + False + >>> check_tag_name("CELL.3ENABLE") + False + >>> check_tag_name("FEATURE.12.ON") + False + ''' + + for part in tag.split("."): + if not len(part) or TAG_PART_RE.match(part) is None: + return False + + return True + def run(fn_ins, fn_out, strict=False, track_origin=False, verbose=False): # tag to bits @@ -27,6 +57,9 @@ def run(fn_ins, fn_out, strict=False, track_origin=False, verbose=False): assert mode is not None or mode != "always", "strict: got ill defined line: %s" % ( line, ) + if not check_tag_name(tag): + assert not strict, "strict: Invalid tag name '{}'".format(tag) + if tag in tags: orig_bits, orig_line, orig_origin = tags[tag] if orig_bits != bits: