Verifying status words against the standard SDK ones
What changed, and why it matters
This commit adds compile-time checks that make sure the app's internal error/status codes match the ones defined by Ledger's standard software development kit. It does not change any behavior of the app; it only adds safety guards so that future mismatches would be caught when building the code. There is no indication this fixes an active security bug.
No security action required. Treat as normal code-quality hardening. Reviewers may verify that the asserted SDK mappings are correct and that the build still passes on all supported SDK versions.
Security signals we found
No functional code change
No bug fix for a reported vulnerability
Adds compile-time assertions for status-word consistency
No change to cryptographic, parsing, or authorization logic
No vendor security disclosure or advisory referenced
Evidence from the diff
The patch adds _Static_assert() directives in src/boilerplate/sw.h comparing each locally-defined status word (SW_OK, SW_SECURITY_STATUS_NOT_SATISFIED, SW_DENY, SW_INCORRECT_DATA, SW_WRONG_P1P2, SW_WRONG_DATA_LENGTH, SW_INS_NOT_SUPPORTED, SW_CLA_NOT_SUPPORTED) against the corresponding SDK macro from status_words.h. It also updates the unit-test CMake include path to add $ENV{BOLOS_SDK}/include so the SDK header can be found. This is a hardening/quality improvement, not a functional or security fix for a known vulnerability.
Changed components
src/boilerplate/sw.hunit-tests/CMakeLists.txtInspect captured patch +19 / −0
diff --git a/src/boilerplate/sw.h b/src/boilerplate/sw.h
index a61516c..df7fe77 100644
--- a/src/boilerplate/sw.h
+++ b/src/boilerplate/sw.h
@@ -1,25 +1,35 @@
#pragma once
+/* SDK headers */
+#include "status_words.h"
+
/**
* Status word for success.
*/
#define SW_OK 0x9000
+_Static_assert(SW_OK == SWO_SUCCESS, "Status word value does not match with the SDK one");
/**
* Status word for command not valid for security reasons (for example: device needs to be unlocked
* with PIN).
*/
#define SW_SECURITY_STATUS_NOT_SATISFIED 0x6982
+_Static_assert(SW_SECURITY_STATUS_NOT_SATISFIED == SWO_SECURITY_CONDITION_NOT_SATISFIED,
+ "Status word value does not match with the SDK one");
/**
* Status word for denied by user.
*/
#define SW_DENY 0x6985
+_Static_assert(SW_DENY == SWO_CONDITIONS_NOT_SATISFIED,
+ "Status word value does not match with the SDK one");
/**
* Status word for data.
*/
#define SW_INCORRECT_DATA 0x6A80
+_Static_assert(SW_INCORRECT_DATA == SWO_INCORRECT_DATA,
+ "Status word value does not match with the SDK one");
/**
* Status word for request not currently supported (but not otherwise wrong).
@@ -30,11 +40,15 @@
* Status word for incorrect P1 or P2.
*/
#define SW_WRONG_P1P2 0x6A86
+_Static_assert(SW_WRONG_P1P2 == SWO_INCORRECT_P1_P2,
+ "Status word value does not match with the SDK one");
/**
* Status word for either wrong Lc or length of APDU command less than 5.
*/
#define SW_WRONG_DATA_LENGTH 0x6A87
+_Static_assert(SW_WRONG_DATA_LENGTH == SWO_WRONG_DATA_LENGTH,
+ "Status word value does not match with the SDK one");
/**
* Status word for fail in Swap
@@ -45,11 +59,15 @@
* Status word for unknown command with this INS.
*/
#define SW_INS_NOT_SUPPORTED 0x6D00
+_Static_assert(SW_INS_NOT_SUPPORTED == SWO_INVALID_INS,
+ "Status word value does not match with the SDK one");
/**
* Status word for instruction class is different than CLA.
*/
#define SW_CLA_NOT_SUPPORTED 0x6E00
+_Static_assert(SW_CLA_NOT_SUPPORTED == SWO_INVALID_CLA,
+ "Status word value does not match with the SDK one");
/**
* Status word for wrong response length (buffer too small or too big).
diff --git a/unit-tests/CMakeLists.txt b/unit-tests/CMakeLists.txt
index cd5882a..e617edf 100644
--- a/unit-tests/CMakeLists.txt
+++ b/unit-tests/CMakeLists.txt
@@ -44,6 +44,7 @@ include_directories(../src/boilerplate)
include_directories(mock_includes)
include_directories(libs)
include_directories($ENV{BOLOS_SDK})
+include_directories($ENV{BOLOS_SDK}/include)
include_directories($ENV{BOLOS_SDK}/lib_standard_app)
add_executable(test_bitvector test_bitvector.c)
Why this scored 14/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.