Skip to content

Commit 6b4f8c9

Browse files
committed
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.
1 parent 6c306b6 commit 6b4f8c9

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
@@ -1217,7 +1217,8 @@ def get_openssl_version(o):
12171217
"""Parse OpenSSL version from opensslv.h header file.
12181218
12191219
Returns the version as a number matching OPENSSL_VERSION_NUMBER format:
1220-
0xMNN00PPSL where M=major, NN=minor, PP=patch, S=status(0xf=release,0x0=pre), L=0
1220+
0xMNN00PPSL where M=major, NN=minor, PP=patch, S=status(0xf=release,0x0=pre),
1221+
L denotes as a long type literal
12211222
"""
12221223

12231224
try:
@@ -1260,6 +1261,14 @@ def get_openssl_version(o):
12601261
minor = int(macros.get('OPENSSL_VERSION_MINOR', '0'))
12611262
patch = int(macros.get('OPENSSL_VERSION_PATCH', '0'))
12621263

1264+
# If major, minor and patch are all 0, this is probably OpenSSL < 3.
1265+
if (major, minor, patch) == (0, 0, 0):
1266+
version_number = macros.get('OPENSSL_VERSION_NUMBER')
1267+
# Prior to OpenSSL 3 the value should be in the format 0xMNN00PPSL.
1268+
# If it is, we need to strip the `L` suffix prior to parsing.
1269+
if version_number[:2] == "0x" and version_number[-1] == "L":
1270+
return int(version_number[:-1], 16)
1271+
12631272
# Check if it's a pre-release (has non-empty PRE_RELEASE string)
12641273
pre_release = macros.get('OPENSSL_VERSION_PRE_RELEASE', '""').strip('"')
12651274
status = 0x0 if pre_release else 0xf

0 commit comments

Comments
 (0)