@@ -15,6 +15,11 @@ include("cmake/compat_find.cmake")
1515find_package (Threads REQUIRED)
1616find_package (CapnProto 0.7 REQUIRED NO_MODULE)
1717
18+ # Cap'n Proto compatibility checks 
19+ set (CAPNPROTO_ISSUES "" )
20+ set (CAPNPROTO_CVE_AFFECTED FALSE )
21+ set (CAPNPROTO_CLANG_INCOMPATIBLE FALSE )
22+ 
1823# Check for list-of-pointers memory access bug from Nov 2022 
1924# https://nvd.nist.gov/vuln/detail/CVE-2022-46149 
2025# https://github.com/advisories/GHSA-qqff-4vw4-f6hx 
@@ -29,11 +34,43 @@ if(CapnProto_VERSION STREQUAL "0.7.0"
2934   OR  CapnProto_VERSION STREQUAL  "0.10.0" 
3035   OR  CapnProto_VERSION STREQUAL  "0.10.1" 
3136   OR  CapnProto_VERSION STREQUAL  "0.10.2" )
37+   set (CAPNPROTO_CVE_AFFECTED TRUE )
38+   string (APPEND  CAPNPROTO_ISSUES "- CVE-2022-46149 security vulnerability (details: https://github.com/advisories/GHSA-qqff-4vw4-f6hx)\n " )
39+ endif ()
40+ 
41+ # Check for Cap'n Proto / Clang / C++20 incompatibility 
42+ # Cap'n Proto 0.9.x and 0.10.x are incompatible with Clang 16+ when using C++20 
43+ # due to P2468R2 implementation. This was fixed in Cap'n Proto 1.0+. 
44+ # See: https://github.com/bitcoin-core/libmultiprocess/issues/199 
45+ if ((CapnProto_VERSION VERSION_GREATER_EQUAL  "0.9.0" ) AND 
46+    (CapnProto_VERSION VERSION_LESS  "1.0.0" ) AND 
47+    (CMAKE_CXX_COMPILER_ID STREQUAL  "Clang" ) AND 
48+    (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL  "16" ) AND 
49+    (CMAKE_CXX_STANDARD EQUAL  20))
50+   set (CAPNPROTO_CLANG_INCOMPATIBLE TRUE )
51+   string (APPEND  CAPNPROTO_ISSUES "- Incompatible with Clang ${CMAKE_CXX_COMPILER_VERSION}  when using C++20\n " )
52+ endif ()
53+ 
54+ if (CAPNPROTO_CVE_AFFECTED OR  CAPNPROTO_CLANG_INCOMPATIBLE)
55+   set (RESOLUTION_OPTIONS "" )
56+ 
57+   # Fixes both issues 
58+   string (APPEND  RESOLUTION_OPTIONS "  - Upgrade to Cap'n Proto version 1.0 or newer (recommended)\n " )
59+ 
60+   if (CAPNPROTO_CVE_AFFECTED AND  NOT  CAPNPROTO_CLANG_INCOMPATIBLE)
61+     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 " )
62+   elseif (CAPNPROTO_CLANG_INCOMPATIBLE AND  NOT  CAPNPROTO_CVE_AFFECTED)
63+     string (APPEND  RESOLUTION_OPTIONS "  - Use GCC instead of Clang\n " )
64+   endif ()
65+ 
66+   string (APPEND  RESOLUTION_OPTIONS "  - For Bitcoin Core compilation build with -DENABLE_IPC=OFF to disable multiprocess support\n " )
67+ 
3268  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-   " )
69+     "The version of Cap'n Proto detected: ${CapnProto_VERSION}  has known compatibility issues:\n " 
70+     "${CAPNPROTO_ISSUES} " 
71+     "To resolve, choose one of the following:\n " 
72+     "${RESOLUTION_OPTIONS} " 
73+   )
3774endif ()
3875
3976set (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