Moving the ticker to the end for the swap case
What changed, and why it matters
This commit changes how a cryptocurrency amount is formatted on screen during a swap operation. Previously the coin ticker (like 'BTC') appeared before the amount; now it appears after. The change also replaces hard-coded number 8 with a named constant and uses a safer array initialization. There is no direct evidence this fixes a security vulnerability.
No security action required. Treat as a normal UI/UX formatting change. If reviewing for security, verify that printable_amount buffer size is sufficient for the new '<amount> <ticker>' layout, including the added space and null terminator.
Security signals we found
No security-relevant keywords in commit title or message
Buffer size constant introduced but not changed
String formatting reorder only
No new input validation or sanitization
Evidence from the diff
The patch modifies handle_get_printable_amount in the Ledger Bitcoin app’s swap flow. It reorders the output string from ‘
Changed components
src/swap/handle_get_printable_amount.cInspect captured patch +14 / −10
diff --git a/src/swap/handle_get_printable_amount.c b/src/swap/handle_get_printable_amount.c
index 3e50c0f..c92967d 100644
--- a/src/swap/handle_get_printable_amount.c
+++ b/src/swap/handle_get_printable_amount.c
@@ -5,22 +5,26 @@
#include "btchip_bcd.h"
+#define MAX_NON_PRINTABLE_AMOUNT_LEN 8
+
int handle_get_printable_amount(get_printable_amount_parameters_t *params) {
params->printable_amount[0] = 0;
- if (params->amount_length > 8) {
+ if (params->amount_length > MAX_NON_PRINTABLE_AMOUNT_LEN) {
PRINTF("Amount is too big");
return 0;
}
- unsigned char amount[8];
- memset(amount, 0, 8);
- memcpy(amount + (8 - params->amount_length), params->amount, params->amount_length);
+ unsigned char amount[MAX_NON_PRINTABLE_AMOUNT_LEN] = {0};
+ /* Amount + ' ' + ticker */
+ memcpy(amount + (MAX_NON_PRINTABLE_AMOUNT_LEN - params->amount_length),
+ params->amount,
+ params->amount_length);
+ int res_length =
+ btchip_convert_hex_amount_to_displayable_no_globals(amount,
+ (uint8_t *) params->printable_amount);
+ params->printable_amount[res_length] = ' ';
size_t coin_name_length = strlen(COIN_COINID_SHORT);
- memmove(params->printable_amount, COIN_COINID_SHORT, coin_name_length);
- params->printable_amount[coin_name_length] = ' ';
- int res_length = btchip_convert_hex_amount_to_displayable_no_globals(
- amount,
- (uint8_t *) params->printable_amount + coin_name_length + 1);
+ memmove(¶ms->printable_amount[res_length + 1], COIN_COINID_SHORT, coin_name_length);
params->printable_amount[res_length + coin_name_length + 1] = '\0';
return 1;
-}
\ No newline at end of file
+}
Why this scored 17/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.