Skip to content

Commit 13424cf

Browse files
committed
Merge #205: cmake: check for Cap'n Proto / Clang / C++20 incompatibility
657d806 cmake: capnproto pkg missing helpful error (will) d314057 cmake: check for Cap'n Proto / Clang / C++20 incompatibility (will) Pull request description: Cap'n Proto 0.9.x and 0.10.x are incompatible with Clang 16+ when using C++20 due to P2468R2 implementation. This was fixed in Cap'n Proto 1.0+. Generate a helpful error when these combinations are detected. See: #199 for more context ACKs for top commit: ryanofsky: Code review ACK 657d806. Thanks for these changes! I think they should very helpful and prevent unnecessary confusion. Tree-SHA512: 1061ad9cc7823650112a5b853abe845300bed6ed70b2c15c2e71c4ad1c327491e04b66d98f402f1d5ec50caeab3bc8269e5228995ce599504ea87169ff872166
2 parents 72dce11 + 657d806 commit 13424cf

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

CMakeLists.txt

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,20 @@ endif()
1313
include("cmake/compat_find.cmake")
1414

1515
find_package(Threads REQUIRED)
16-
find_package(CapnProto 0.7 REQUIRED NO_MODULE)
16+
find_package(CapnProto 0.7 QUIET NO_MODULE)
17+
if(NOT CapnProto_FOUND)
18+
message(FATAL_ERROR
19+
"Cap'n Proto is required but was not found.\n"
20+
"To resolve, choose one of the following:\n"
21+
" - Install Cap'n Proto (version 1.0+ recommended)\n"
22+
" - For Bitcoin Core compilation build with -DENABLE_IPC=OFF to disable multiprocess support\n"
23+
)
24+
endif()
25+
26+
# Cap'n Proto compatibility checks
27+
set(CAPNPROTO_ISSUES "")
28+
set(CAPNPROTO_CVE_AFFECTED FALSE)
29+
set(CAPNPROTO_CLANG_INCOMPATIBLE FALSE)
1730

1831
# Check for list-of-pointers memory access bug from Nov 2022
1932
# https://nvd.nist.gov/vuln/detail/CVE-2022-46149
@@ -29,11 +42,43 @@ if(CapnProto_VERSION STREQUAL "0.7.0"
2942
OR CapnProto_VERSION STREQUAL "0.10.0"
3043
OR CapnProto_VERSION STREQUAL "0.10.1"
3144
OR CapnProto_VERSION STREQUAL "0.10.2")
45+
set(CAPNPROTO_CVE_AFFECTED TRUE)
46+
string(APPEND CAPNPROTO_ISSUES "- CVE-2022-46149 security vulnerability (details: https://github.com/advisories/GHSA-qqff-4vw4-f6hx)\n")
47+
endif()
48+
49+
# Check for Cap'n Proto / Clang / C++20 incompatibility
50+
# Cap'n Proto 0.9.x and 0.10.x are incompatible with Clang 16+ when using C++20
51+
# due to P2468R2 implementation. This was fixed in Cap'n Proto 1.0+.
52+
# See: https://github.com/bitcoin-core/libmultiprocess/issues/199
53+
if((CapnProto_VERSION VERSION_GREATER_EQUAL "0.9.0") AND
54+
(CapnProto_VERSION VERSION_LESS "1.0.0") AND
55+
(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND
56+
(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "16") AND
57+
(CMAKE_CXX_STANDARD EQUAL 20))
58+
set(CAPNPROTO_CLANG_INCOMPATIBLE TRUE)
59+
string(APPEND CAPNPROTO_ISSUES "- Incompatible with Clang ${CMAKE_CXX_COMPILER_VERSION} when using C++20\n")
60+
endif()
61+
62+
if(CAPNPROTO_CVE_AFFECTED OR CAPNPROTO_CLANG_INCOMPATIBLE)
63+
set(RESOLUTION_OPTIONS "")
64+
65+
# Fixes both issues
66+
string(APPEND RESOLUTION_OPTIONS " - Upgrade to Cap'n Proto version 1.0 or newer (recommended)\n")
67+
68+
if(CAPNPROTO_CVE_AFFECTED AND NOT CAPNPROTO_CLANG_INCOMPATIBLE)
69+
string(APPEND RESOLUTION_OPTIONS " - Upgrade to a patched minor version (0.7.1, 0.8.1, 0.9.2, 0.10.3, or later)\n")
70+
elseif(CAPNPROTO_CLANG_INCOMPATIBLE AND NOT CAPNPROTO_CVE_AFFECTED)
71+
string(APPEND RESOLUTION_OPTIONS " - Use GCC instead of Clang\n")
72+
endif()
73+
74+
string(APPEND RESOLUTION_OPTIONS " - For Bitcoin Core compilation build with -DENABLE_IPC=OFF to disable multiprocess support\n")
75+
3276
message(FATAL_ERROR
33-
"Cap'n Proto ${CapnProto_VERSION} is affected by CVE-2022-46149.\n"
34-
"Please install an updated package.\n"
35-
"Details: https://github.com/advisories/GHSA-qqff-4vw4-f6hx
36-
")
77+
"The version of Cap'n Proto detected: ${CapnProto_VERSION} has known compatibility issues:\n"
78+
"${CAPNPROTO_ISSUES}"
79+
"To resolve, choose one of the following:\n"
80+
"${RESOLUTION_OPTIONS}"
81+
)
3782
endif()
3883

3984
set(MPGEN_EXECUTABLE "" CACHE FILEPATH "If specified, should be full path to an external mpgen binary to use rather than the one built internally.")

0 commit comments

Comments
 (0)