1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-08-01 19:38:33 +00:00

fix(legacy): stop processing after definition chain ID mismatch

This commit is contained in:
Martin Novak 2022-10-13 13:27:24 +02:00
parent 8914b2afd3
commit 43438395f3
2 changed files with 25 additions and 15 deletions

View File

@ -242,7 +242,8 @@ bool _get_EthereumNetworkInfo(
// chain_id mismatch - error and reset definition
fsm_sendFailure(FailureType_Failure_DataError,
_("Invalid network definition - chain IDs not equal."));
_set_EthereumNetworkInfo_to_builtin(ref_chain_id, network);
_set_EthereumNetworkInfo_to_builtin(CHAIN_ID_UNKNOWN, network);
return false;
} else {
// chain_id does match the reference one (if provided) so prepend one
// space character to symbol, terminate it (encoded definitions does not
@ -251,15 +252,14 @@ bool _get_EthereumNetworkInfo(
sizeof(network->shortcut) - 2);
network->shortcut[0] = ' ';
network->shortcut[sizeof(network->shortcut) - 1] = 0;
return true;
}
} else {
// decoding failed - reset network definition
_set_EthereumNetworkInfo_to_builtin(ref_chain_id, network);
_set_EthereumNetworkInfo_to_builtin(CHAIN_ID_UNKNOWN, network);
}
}
return network->chain_id == CHAIN_ID_UNKNOWN ? false : true;
return true;
}
void _get_EthereumTokenInfo(
@ -322,7 +322,13 @@ const EthereumDefinitions *get_EthereumDefinitions(
const uint64_t ref_chain_id, const char *ref_address) {
static EthereumDefinitions defs;
if (_get_EthereumNetworkInfo(encoded_network, ref_chain_id, &defs.network)) {
if (!_get_EthereumNetworkInfo(encoded_network, ref_chain_id, &defs.network)) {
// error while decoding - chain IDs mismatch
return NULL;
}
if (strncmp(defs.network.shortcut, UNKNOWN_NETWORK_SHORTCUT,
sizeof(defs.network.shortcut)) != 0) {
// we have found network definition, we can try to load token definition
_get_EthereumTokenInfo(encoded_token, ref_chain_id, ref_address,
&defs.token);

View File

@ -47,6 +47,10 @@ void fsm_msgEthereumGetPublicKey(const EthereumGetPublicKey *msg) {
const EthereumDefinitions *defs =
get_EthereumDefinitions(encoded_network, NULL, CHAIN_ID_UNKNOWN, NULL);
if (!defs) {
layoutHome();
return;
}
// we use Bitcoin-like format for ETH
const CoinInfo *coin = fsm_getCoin(true, "Bitcoin");
@ -119,8 +123,8 @@ void fsm_msgEthereumSignTx(const EthereumSignTx *msg) {
get_EthereumDefinitions(encoded_network, encoded_token, msg->chain_id,
msg->has_to ? msg->to : NULL);
if (!fsm_ethereumCheckPath(msg->address_n_count, msg->address_n, false,
defs)) {
if (!defs || !fsm_ethereumCheckPath(msg->address_n_count, msg->address_n,
false, defs)) {
layoutHome();
return;
}
@ -155,8 +159,8 @@ void fsm_msgEthereumSignTxEIP1559(const EthereumSignTxEIP1559 *msg) {
get_EthereumDefinitions(encoded_network, encoded_token, msg->chain_id,
msg->has_to ? msg->to : NULL);
if (!fsm_ethereumCheckPath(msg->address_n_count, msg->address_n, false,
defs)) {
if (!defs || !fsm_ethereumCheckPath(msg->address_n_count, msg->address_n,
false, defs)) {
layoutHome();
return;
}
@ -190,8 +194,8 @@ void fsm_msgEthereumGetAddress(const EthereumGetAddress *msg) {
const EthereumDefinitions *defs =
get_EthereumDefinitions(encoded_network, NULL, CHAIN_ID_UNKNOWN, NULL);
if (!fsm_ethereumCheckPath(msg->address_n_count, msg->address_n, false,
defs)) {
if (!defs || !fsm_ethereumCheckPath(msg->address_n_count, msg->address_n,
false, defs)) {
layoutHome();
return;
}
@ -263,8 +267,8 @@ void fsm_msgEthereumSignMessage(const EthereumSignMessage *msg) {
const EthereumDefinitions *defs =
get_EthereumDefinitions(encoded_network, NULL, CHAIN_ID_UNKNOWN, NULL);
if (!fsm_ethereumCheckPath(msg->address_n_count, msg->address_n, false,
defs)) {
if (!defs || !fsm_ethereumCheckPath(msg->address_n_count, msg->address_n,
false, defs)) {
layoutHome();
return;
}
@ -359,8 +363,8 @@ void fsm_msgEthereumSignTypedHash(const EthereumSignTypedHash *msg) {
const EthereumDefinitions *defs =
get_EthereumDefinitions(encoded_network, NULL, CHAIN_ID_UNKNOWN, NULL);
if (!fsm_ethereumCheckPath(msg->address_n_count, msg->address_n, false,
defs)) {
if (!defs || !fsm_ethereumCheckPath(msg->address_n_count, msg->address_n,
false, defs)) {
layoutHome();
return;
}