What changed, and why it matters
This commit fixes a build-configuration problem in Ledger's Bitcoin app. Two source files now explicitly include the SDK header that defines TARGET_* constants (such as TARGET_NANOX, TARGET_STAX, TARGET_FLEX), and the build adds the correct include path for unit tests. Without these constants, the code could silently fall back to default values, potentially changing behavior on different Ledger devices. The change also adds compile-time #error checks so the problem cannot happen silently again.
Verify that all other source files using TARGET_* macros include bolos_target.h or inherit it from a common header, and that CI builds for each supported device (Nano S/S+, X, Stax, Flex) fail if the constants are missing. Treat this as a build-hardening fix rather than an active vulnerability.
Security signals we found
Conditional compilation depends on device-specific TARGET_* macros
Missing SDK header could cause silent fallback to default code paths
Compile-time guard added to fail closed if constants are unavailable
Build system include path corrected for unit-test compilation
No direct memory-safety or cryptographic bug visible in diff
Evidence from the diff
The patch adds #include “bolos_target.h” to src/constants.h and src/ui/display.h, and adds $ENV{BOLOS_SDK}/target/nanos2/include to the unit-test CMake include path. It also adds #ifndef TARGET_ID #error … guards before conditional compilation blocks that depend on TARGET_NANOX / TARGET_STAX / TARGET_FLEX. The intent is to ensure TARGET_* device constants are always available when those headers are compiled, preventing silent miscompilation where a device-specific branch is not taken because the macro is undefined.
Changed components
src/constants.hsrc/ui/display.hunit-tests/CMakeLists.txtLedger Bitcoin app build configurationInspect captured patch +9 / −0
diff --git a/src/constants.h b/src/constants.h
index bb3ea2b..0953bac 100644
--- a/src/constants.h
+++ b/src/constants.h
@@ -2,6 +2,7 @@
/* SDK headers */
#include "bip32.h"
+#include "bolos_target.h"
/**
* Instruction class of the Bitcoin application.
@@ -59,6 +60,9 @@
* On the Nano X, the stack size is limited to 8K at the OS level,
* so the stack consumption has to be limited as well.
*/
+#ifndef TARGET_ID
+#error "bolos_target.h must be included (TARGET_* constants unavailable)"
+#endif
#ifdef TARGET_NANOX
#define MAX_EXT_OUTPUT_SIMPLIFIED_NUMBER 8
#else
diff --git a/src/ui/display.h b/src/ui/display.h
index 85d8163..72b80c1 100644
--- a/src/ui/display.h
+++ b/src/ui/display.h
@@ -4,6 +4,7 @@
/* SDK headers */
#include "bip32.h"
+#include "bolos_target.h"
#include "format.h"
/* Local headers */
@@ -20,6 +21,9 @@
// Displayed message length - if the message is too long we will not display it
#define MAX_DISPLAYBLE_MESSAGE_LENGTH (10 * MESSAGE_CHUNK_SIZE)
+#ifndef TARGET_ID
+#error "bolos_target.h must be included (TARGET_* constants unavailable)"
+#endif
#if defined(TARGET_STAX) || defined(TARGET_FLEX)
#define ICON_APP_IMPORTANT IMPORTANT_CIRCLE_ICON
#define ICON_APP_WARNING LARGE_WARNING_ICON
diff --git a/unit-tests/CMakeLists.txt b/unit-tests/CMakeLists.txt
index 4316dd8..74cfb67 100644
--- a/unit-tests/CMakeLists.txt
+++ b/unit-tests/CMakeLists.txt
@@ -80,6 +80,7 @@ include_directories(libs)
include_directories($ENV{BOLOS_SDK})
include_directories($ENV{BOLOS_SDK}/include)
include_directories($ENV{BOLOS_SDK}/lib_standard_app)
+include_directories($ENV{BOLOS_SDK}/target/nanos2/include)
# Include paths shared by every target under ../src/handler.
set(HANDLER_INCLUDES ../src/handler ../src/handler/lib ../src/common)
Why this scored 35/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.