main: fix error handling for debug handshake
What changed, and why it matters
This commit fixes a missing 'goto cleanup' after a failed attempt to save encrypted key data during a debug handshake. Without the fix, the code would continue running after reporting an error, potentially leaving sensitive key material in memory or skipping cleanup steps. The change ensures the function exits cleanly and securely when storage fails.
Review the full debug_handshake function for any other missing error-path exits, ensure cleanup label zeroizes sensitive stack/heap key material, and consider whether the debug handshake feature should be gated or disabled in production firmware builds.
Security signals we found
Missing error-path termination leading to fall-through after a security-critical failure
Potential failure to clean up sensitive key material after flash storage error
Assertion on keychain state could be reached with inconsistent state
Evidence from the diff
In main/process/debug_handshake.c, after jade_process_reject_message() reports an internal error for failing to store encrypted key data, the function previously fell through to subsequent code including JADE_ASSERT(keychain_has_pin()) and further operations. The patch adds ‘goto cleanup;’ so the error path properly terminates the handshake and releases resources. This prevents possible use of partially initialized or uncommitted keychain state and ensures cleanup runs.
Changed components
main/process/debug_handshake.cDebug handshake processKeychain/key storage initialization pathInspect captured patch +1 / −0
diff --git a/main/process/debug_handshake.c b/main/process/debug_handshake.c
index 961c34e..0b25ff7 100644
--- a/main/process/debug_handshake.c
+++ b/main/process/debug_handshake.c
@@ -93,6 +93,7 @@ void debug_handshake(void* process_ptr)
JADE_LOGE("Failed to store key data encrypted in flash memory!");
jade_process_reject_message(
process, CBOR_RPC_INTERNAL_ERROR, "Failed to store key data encrypted in flash memory");
+ goto cleanup;
}
JADE_ASSERT(keychain_has_pin());
Why this scored 42/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.