From 6b4f8c922295ba4d5aad602d7f9d6166eb608439 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Tue, 18 Nov 2025 12:51:56 +0000 Subject: [PATCH] build: fix OpenSSL version parsing for OpenSSL < 3 OpenSSL versions before 3.0.0 do not define - `OPENSSL_VERSION_MAJOR` - `OPENSSL_VERSION_MINOR` - `OPENSSL_VERSION_PATCH` in `openssl/opensslv.h`. For these versions, `OPENSSL_VERSION_NUMBER` is a literal which we can parse directly. --- configure.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/configure.py b/configure.py index a752897e90aa25..63b0d3628ad725 100755 --- a/configure.py +++ b/configure.py @@ -1217,7 +1217,8 @@ def get_openssl_version(o): """Parse OpenSSL version from opensslv.h header file. Returns the version as a number matching OPENSSL_VERSION_NUMBER format: - 0xMNN00PPSL where M=major, NN=minor, PP=patch, S=status(0xf=release,0x0=pre), L=0 + 0xMNN00PPSL where M=major, NN=minor, PP=patch, S=status(0xf=release,0x0=pre), + L denotes as a long type literal """ try: @@ -1260,6 +1261,14 @@ def get_openssl_version(o): minor = int(macros.get('OPENSSL_VERSION_MINOR', '0')) patch = int(macros.get('OPENSSL_VERSION_PATCH', '0')) + # If major, minor and patch are all 0, this is probably OpenSSL < 3. + if (major, minor, patch) == (0, 0, 0): + version_number = macros.get('OPENSSL_VERSION_NUMBER') + # Prior to OpenSSL 3 the value should be in the format 0xMNN00PPSL. + # If it is, we need to strip the `L` suffix prior to parsing. + if version_number[:2] == "0x" and version_number[-1] == "L": + return int(version_number[:-1], 16) + # Check if it's a pre-release (has non-empty PRE_RELEASE string) pre_release = macros.get('OPENSSL_VERSION_PRE_RELEASE', '""').strip('"') status = 0x0 if pre_release else 0xf