What changed, and why it matters
This commit is a routine code cleanup that renames and consolidates helper functions used to send response messages from the Ledger Bitcoin app. It removes a few redundant wrapper functions and updates the documentation comments. There is no indication of a security fix or behavior change.
No security action required. Treat as normal refactoring; review as part of standard code-quality process.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change refactors the APDU response I/O helpers in src/boilerplate/io_ext.c/h. Functions io_reset_response(), io_set_response(), and the old io_confirm_response() are removed or renamed. The old io_send_response(void*, size_t, uint16_t) is replaced by a stateful io_send_response(void) that transmits whatever was already built via io_add_to_response()/io_finalize_response(). Callers in dispatcher.c and io_send_sw() are updated accordingly. The diff shows only function-call reorganization; no logic changes to buffer handling, length checks, or status-word processing.
Changed components
src/boilerplate/dispatcher.csrc/boilerplate/io_ext.csrc/boilerplate/io_ext.hInspect captured patch +21 / −45
diff --git a/src/boilerplate/dispatcher.c b/src/boilerplate/dispatcher.c
index 8f17279..00194fe 100644
--- a/src/boilerplate/dispatcher.c
+++ b/src/boilerplate/dispatcher.c
@@ -52,7 +52,7 @@ static void finalize_response(uint16_t sw) {
}
static void send_response() {
- io_confirm_response();
+ io_send_response();
}
static void set_ui_dirty() {
diff --git a/src/boilerplate/io_ext.c b/src/boilerplate/io_ext.c
index bb72c33..d419c0e 100644
--- a/src/boilerplate/io_ext.c
+++ b/src/boilerplate/io_ext.c
@@ -131,19 +131,7 @@ void io_finalize_response(uint16_t sw) {
}
}
-void io_reset_response() {
- G_output_len = 0;
-}
-
-void io_set_response(const void *rdata, size_t rdata_len, uint16_t sw) {
- io_reset_response();
- if (rdata != NULL) {
- io_add_to_response(rdata, rdata_len);
- }
- io_finalize_response(sw);
-}
-
-int io_confirm_response() {
+int io_send_response() {
int ret;
ret = io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, G_output_len);
@@ -152,11 +140,8 @@ int io_confirm_response() {
return ret;
}
-int io_send_response(void *rdata, size_t rdata_len, uint16_t sw) {
- io_set_response(rdata, rdata_len, sw);
- return io_confirm_response();
-}
-
int io_send_sw(uint16_t sw) {
- return io_send_response(NULL, 0, sw);
+ G_output_len = 0;
+ io_finalize_response(sw);
+ return io_send_response();
}
diff --git a/src/boilerplate/io_ext.h b/src/boilerplate/io_ext.h
index 997fa6d..f0d14ec 100644
--- a/src/boilerplate/io_ext.h
+++ b/src/boilerplate/io_ext.h
@@ -63,48 +63,39 @@ void io_reset_timeouts();
void io_show_processing_screen();
/**
- * TODO: docs
- */
-void io_reset_response();
-
-/**
- * TODO: docs
+ * Append data to the APDU response buffer (G_io_apdu_buffer).
+ *
+ * @param[in] rdata
+ * Pointer to the data to append.
+ * @param[in] rdata_len
+ * Length of data to append.
*/
void io_add_to_response(const void *rdata, size_t rdata_len);
/**
- * TODO: docs
+ * Finalize the APDU response by appending the status word.
+ * Must be called after all io_add_to_response() calls are done.
+ *
+ * @param[in] sw
+ * Status word of APDU response.
*/
void io_finalize_response(uint16_t sw);
-/* TODO: docs */
-void io_set_response(const void *rdata, size_t rdata_len, uint16_t sw);
-
-/* TODO: docs */
-int io_confirm_response(void);
-
/**
- * Send APDU response (response data + status word) by filling G_io_apdu_buffer.
- *
- * @param[in] rdata
- * Pointer to the response.
- * @param[in] rdata_len
- * Length of response.
- * @param[in] sw
- * Status word of APDU response.
+ * Send the previously prepared APDU response via io_exchange.
+ * The response must have been built with io_add_to_response()/io_finalize_response()
+ * before calling this function.
*
* @return zero or positive integer if success, -1 otherwise.
- *
*/
-int io_send_response(void *rdata, size_t rdata_len, uint16_t sw);
+int io_send_response(void);
/**
- * Send APDU response (only status word) by filling G_io_apdu_buffer.
+ * Send APDU response containing only a status word (no data).
*
* @param[in] sw
* Status word of APDU response.
*
* @return zero or positive integer if success, -1 otherwise.
- *
*/
int io_send_sw(uint16_t sw);
Why this scored 15/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.