Skip to content

Commit e000273

Browse files
Merge pull request #276 from LedgerHQ/apr/bugfix/nft_security_review
NFT feature security review
2 parents d2b2682 + 8739b29 commit e000273

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+232
-224
lines changed

src/apdu_constants.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#ifndef _APDU_CONSTANTS_H_
2+
#define _APDU_CONSTANTS_H_
3+
14
#include "shared_context.h"
25

36
#define APP_FLAG_DATA_ALLOWED 0x01
@@ -156,3 +159,5 @@ void handleStarkwareUnsafeSign(uint8_t p1,
156159
unsigned int *tx);
157160

158161
#endif
162+
163+
#endif // _APDU_CONSTANTS_H_

src/chainConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ typedef struct chain_config_s {
6969

7070
#define ETHEREUM_MAINNET_CHAINID 1
7171

72-
#endif /* _CHAIN_CONFIG_H_ */
72+
#endif // _CHAIN_CONFIG_H_

src/eth_plugin_handler.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ void eth_plugin_prepare_query_contract_UI(ethQueryContractUI_t *queryContractUI,
4848
memset((uint8_t *) queryContractUI, 0, sizeof(ethQueryContractUI_t));
4949

5050
// If no extra information was found, set the pointer to NULL
51-
if (allzeroes(&tmpCtx.transactionContext.extraInfo[1], sizeof(union extraInfo_t))) {
51+
if (NO_EXTRA_INFO(tmpCtx, 1)) {
5252
queryContractUI->item1 = NULL;
5353
} else {
5454
queryContractUI->item1 = &tmpCtx.transactionContext.extraInfo[1];
5555
}
5656

5757
// If no extra information was found, set the pointer to NULL
58-
if (allzeroes(&tmpCtx.transactionContext.extraInfo[0], sizeof(union extraInfo_t))) {
58+
if (NO_EXTRA_INFO(tmpCtx, 0)) {
5959
queryContractUI->item2 = NULL;
6060
} else {
6161
queryContractUI->item2 = &tmpCtx.transactionContext.extraInfo[0];

src/eth_plugin_handler.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
#ifndef __ETH_PLUGIN_HANDLER_H__
1+
#ifndef _ETH_PLUGIN_HANDLER_H_
2+
#define _ETH_PLUGIN_HANDLER_H_
23

34
#include "eth_plugin_interface.h"
45

6+
#define NO_EXTRA_INFO(ctx, idx) \
7+
(allzeroes(&(ctx.transactionContext.extraInfo[idx]), sizeof(extraInfo_t)))
8+
59
void eth_plugin_prepare_init(ethPluginInitContract_t *init, uint8_t *selector, uint32_t dataSize);
610
void eth_plugin_prepare_provide_parameter(ethPluginProvideParameter_t *provideParameter,
711
uint8_t *parameter,
@@ -27,4 +31,4 @@ eth_plugin_result_t eth_plugin_call(int method, void *parameter);
2731

2832
void plugin_ui_start(void);
2933

30-
#endif
34+
#endif // _ETH_PLUGIN_HANDLER_H_

src/eth_plugin_interface.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#ifndef __ETH_PLUGIN_INTERFACE_H__
2-
3-
#define __ETH_PLUGIN_INTERFACE_H__
1+
#ifndef _ETH_PLUGIN_INTERFACE_H_
2+
#define _ETH_PLUGIN_INTERFACE_H_
43

54
#include "os.h"
65
#include "cx.h"
@@ -179,4 +178,4 @@ typedef struct ethQueryContractUI_t {
179178

180179
} ethQueryContractUI_t;
181180

182-
#endif
181+
#endif // _ETH_PLUGIN_INTERFACE_H_

src/eth_plugin_internal.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <string.h>
12
#include "eth_plugin_internal.h"
23

34
bool erc20_plugin_available_check(void);

src/eth_plugin_internal.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#ifndef __ETH_PLUGIN_INTERNAL_H__
1+
#ifndef _ETH_PLUGIN_INTERNAL_H_
2+
#define _ETH_PLUGIN_INTERNAL_H_
23

4+
#include <stdint.h>
5+
#include <stdbool.h>
36
#include "eth_plugin_interface.h"
47

58
#define SELECTOR_SIZE 4
@@ -45,4 +48,4 @@ extern const uint8_t* const STARKWARE_SELECTORS[NUM_STARKWARE_SELECTORS];
4548

4649
extern internalEthPlugin_t const INTERNAL_ETH_PLUGINS[];
4750

48-
#endif
51+
#endif // _ETH_PLUGIN_INTERNAL_H_

src/handle_check_address.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66

77
#define ZERO(x) memset(&x, 0, sizeof(x))
88

9-
static int os_strcmp(const char* s1, const char* s2) {
10-
size_t size = strlen(s1) + 1;
11-
return memcmp(s1, s2, size);
12-
}
13-
149
int handle_check_address(check_address_parameters_t* params, chain_config_t* chain_config) {
1510
PRINTF("Params on the address %d\n", (unsigned int) params);
1611
PRINTF("Address to check %s\n", params->address_to_check);
@@ -69,7 +64,7 @@ int handle_check_address(check_address_parameters_t* params, chain_config_t* cha
6964
offset_0x = 2;
7065
}
7166

72-
if (os_strcmp(locals_union1.address, params->address_to_check + offset_0x) != 0) {
67+
if (strcmp(locals_union1.address, params->address_to_check + offset_0x) != 0) {
7368
PRINTF("Addresses don't match\n");
7469
return 0;
7570
}

src/handle_swap_sign_transaction.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include "handle_swap_sign_transaction.h"
2-
#include "usbd_core.h"
1+
#include "os_io_seproxyhal.h"
32
#include "ux.h"
3+
#include "handle_swap_sign_transaction.h"
44
#include "shared_context.h"
55
#include "utils.h"
66

@@ -79,4 +79,4 @@ void handle_swap_sign_transaction(chain_config_t* config) {
7979
BLE_power(1, "Nano X");
8080
#endif // HAVE_BLE
8181
app_main();
82-
}
82+
}

src/main.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ extraInfo_t *getKnownToken(uint8_t *contractAddress) {
386386
}
387387
}
388388
#endif
389-
//
389+
// Works for ERC-20 & NFT tokens since both structs in the union have the
390+
// contract address aligned
390391
for (uint8_t i = 0; i < MAX_ITEMS; i++) {
391392
currentItem = (union extraInfo_t *) &tmpCtx.transactionContext.extraInfo[i].token;
392393
if (tmpCtx.transactionContext.tokenSet[i] &&
@@ -396,15 +397,6 @@ extraInfo_t *getKnownToken(uint8_t *contractAddress) {
396397
}
397398
}
398399

399-
for (uint8_t i = 0; i < MAX_ITEMS; i++) {
400-
currentItem = (union extraInfo_t *) &tmpCtx.transactionContext.extraInfo[i].token;
401-
if (tmpCtx.transactionContext.tokenSet[i] &&
402-
(memcmp(currentItem->nft.contractAddress, contractAddress, ADDRESS_LENGTH) == 0)) {
403-
PRINTF("Token found at index %d\n", i);
404-
return currentItem;
405-
}
406-
}
407-
408400
return NULL;
409401
}
410402

0 commit comments

Comments
 (0)