Commit 8dbc52f3768 for nodejs
commit 8dbc52f37683593100e99a4a64982c874b347ba7
Author: Filip Skokan <panva.ip@gmail.com>
Date: Sat Nov 14 11:10:39 2026 +0100
tools: check crypto backend guard structure
Add build/crypto_backend checks for the OpenSSL provider and BoringSSL
selectors. Require provider guards to name BoringSSL in the same
conditional group. Require #error "Unsupported crypto backend" in the
final #else of groups with alternatives; nested errors do not satisfy
that requirement.
Allow standalone BoringSSL exclusions and ordinary feature, compiler,
and version guards. These checks validate structure without evaluating
backend conditions or API availability.
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/67472
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
diff --git a/tools/cpplint.py b/tools/cpplint.py
index 1e26e3ded39..338bbbce3e4 100755
--- a/tools/cpplint.py
+++ b/tools/cpplint.py
@@ -300,6 +300,7 @@ Syntax: cpplint.py [--verbose=#] [--output=emacs|eclipse|vs7|junit|sed|gsed]
_ERROR_CATEGORIES = [
"build/c++11",
"build/c++17",
+ "build/crypto_backend",
"build/deprecated",
"build/endif_comment",
"build/explicit_make_pair",
@@ -7466,6 +7467,62 @@ def CheckThreadLocalUsage(filename, lines, error):
'NOLINTNEXTLINE(runtime/thread_local).')
+def CheckCryptoBackendUsage(filename, clean_lines, error):
+ """Require explicit BoringSSL guards and unsupported-backend fallbacks.
+
+ Gates excluding BoringSSL must name it instead of using the provider
+ selector. Backend alternatives must explicitly reject unsupported backends;
+ other feature checks remain valid.
+ """
+ provider = re.compile(r'\bNCRYPTO_USE_OPENSSL_PROVIDER\b')
+ boring = re.compile(r'\b(?:NCRYPTO_USE_BORINGSSL|OPENSSL_IS_BORINGSSL)\b')
+ directives = re.compile(
+ r'^\s*#\s*(if|ifdef|ifndef|elif|elifdef|elifndef|else|endif|error)\b(.*)$')
+ stack = []
+ lines = iter(enumerate(clean_lines.lines))
+ for linenum, line in lines:
+ # Preprocessor conditions can span multiple physical lines.
+ while line.endswith('\\'):
+ line = line[:-1] + next(lines, (0, ''))[1]
+ match = directives.match(line)
+ if not match:
+ continue
+ directive, condition = match.groups()
+ if directive in ('if', 'ifdef', 'ifndef'):
+ stack.append({
+ 'linenum': linenum,
+ 'provider': bool(provider.search(condition)),
+ 'boring': bool(boring.search(condition)),
+ 'alternative': False,
+ 'else': False,
+ 'error': False,
+ })
+ elif stack:
+ group = stack[-1]
+ if directive in ('elif', 'elifdef', 'elifndef'):
+ group['provider'] |= bool(provider.search(condition))
+ group['boring'] |= bool(boring.search(condition))
+ group['alternative'] = True
+ elif directive == 'else':
+ group['alternative'] = True
+ group['else'] = True
+ elif directive == 'error' and group['else']:
+ if condition.strip() == '"Unsupported crypto backend"':
+ group['error'] = True
+ elif directive == 'endif':
+ stack.pop()
+ if group['provider'] and not group['boring']:
+ error(filename, group['linenum'], 'build/crypto_backend', 5,
+ 'Crypto backend guards must name BoringSSL explicitly; '
+ 'use #if !NCRYPTO_USE_BORINGSSL for BoringSSL exclusions.')
+ elif ((group['provider'] or group['boring']) and group['alternative'] and
+ not (group['else'] and group['error'])):
+ error(filename, group['linenum'], 'build/crypto_backend', 5,
+ 'Crypto backend alternatives must end with '
+ '#else and #error "Unsupported crypto backend"; '
+ 'use an explicit #elif for each supported backend.')
+
+
def ProcessLine(
filename,
file_extension,
@@ -7631,6 +7688,8 @@ def ProcessFileData(filename, file_extension, lines, error, extra_check_function
CheckThreadLocalUsage(filename, lines, error)
+ CheckCryptoBackendUsage(filename, clean_lines, error)
+
def ProcessConfigOverrides(filename):
"""Loads the configuration files and processes the config overrides.