Skip to content

Commit 0771137

Browse files
authored
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. PR-URL: #60775 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 774e564 commit 0771137

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

configure.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,8 @@ def get_openssl_version(o):
12461246
"""Parse OpenSSL version from opensslv.h header file.
12471247
12481248
Returns the version as a number matching OPENSSL_VERSION_NUMBER format:
1249-
0xMNN00PPSL where M=major, NN=minor, PP=patch, S=status(0xf=release,0x0=pre), L=0
1249+
0xMNN00PPSL where M=major, NN=minor, PP=patch, S=status(0xf=release,0x0=pre),
1250+
L denotes as a long type literal
12501251
"""
12511252

12521253
try:
@@ -1289,6 +1290,14 @@ def get_openssl_version(o):
12891290
minor = int(macros.get('OPENSSL_VERSION_MINOR', '0'))
12901291
patch = int(macros.get('OPENSSL_VERSION_PATCH', '0'))
12911292

1293+
# If major, minor and patch are all 0, this is probably OpenSSL < 3.
1294+
if (major, minor, patch) == (0, 0, 0):
1295+
version_number = macros.get('OPENSSL_VERSION_NUMBER')
1296+
# Prior to OpenSSL 3 the value should be in the format 0xMNN00PPSL.
1297+
# If it is, we need to strip the `L` suffix prior to parsing.
1298+
if version_number[:2] == "0x" and version_number[-1] == "L":
1299+
return int(version_number[:-1], 16)
1300+
12921301
# Check if it's a pre-release (has non-empty PRE_RELEASE string)
12931302
pre_release = macros.get('OPENSSL_VERSION_PRE_RELEASE', '""').strip('"')
12941303
status = 0x0 if pre_release else 0xf

0 commit comments

Comments
 (0)