From 9ba9c21c616e9dee97885cea78dc3d685fe2c872 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 23 May 2024 15:03:43 +0200 Subject: [PATCH] Recognize that a double-inclusion guard is not a config setting Fix PSA_CRYPTO_CONFIG_H being treated as a configuration setting in include/psa/crypto_config.h. Signed-off-by: Gilles Peskine --- scripts/config.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/config.py b/scripts/config.py index c53f9e7fe2..8704bdb51e 100755 --- a/scripts/config.py +++ b/scripts/config.py @@ -396,6 +396,7 @@ class ConfigFile(Config): self.default_path) super().__init__() self.filename = filename + self.inclusion_guard = None self.current_section = 'header' with open(filename, 'r', encoding='utf-8') as file: self.templates = [self._parse_line(line) for line in file] @@ -413,9 +414,11 @@ class ConfigFile(Config): r'(?P(?:\((?:\w|\s|,)*\))?)' + r'(?P\s*)' + r'(?P.*)') + _ifndef_line_regexp = r'#ifndef (?P\w+)' _section_line_regexp = (r'\s*/?\*+\s*[\\@]name\s+SECTION:\s*' + r'(?P
.*)[ */]*') _config_line_regexp = re.compile(r'|'.join([_define_line_regexp, + _ifndef_line_regexp, _section_line_regexp])) def _parse_line(self, line): """Parse a line in mbedtls_config.h and return the corresponding template.""" @@ -426,10 +429,16 @@ class ConfigFile(Config): elif m.group('section'): self.current_section = m.group('section') return line + elif m.group('inclusion_guard') and self.inclusion_guard is None: + self.inclusion_guard = m.group('inclusion_guard') + return line else: active = not m.group('commented_out') name = m.group('name') value = m.group('value') + if name == self.inclusion_guard and value == '': + # The file double-inclusion guard is not an option. + return line template = (name, m.group('indentation'), m.group('define') + name +