@@ -13,7 +13,20 @@ endif()
1313include ("cmake/compat_find.cmake" )
1414
1515find_package (Threads REQUIRED)
16- find_package (CapnProto 0.7 REQUIRED)
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+ )
3782endif ()
3883
3984set (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