Added missing return value checks following recent changes

This commit is contained in:
Alexandre Paillier
2023-10-05 15:01:58 +02:00
parent 9a9e946b50
commit 49da32af8e
14 changed files with 254 additions and 166 deletions

View File

@@ -49,10 +49,12 @@ void handleGetPublicKey(uint8_t p1,
explicit_bzero(&privateKey, sizeof(privateKey));
explicit_bzero(privateKeyData, sizeof(privateKeyData));
io_seproxyhal_io_heartbeat();
getEthAddressStringFromKey(&tmpCtx.publicKeyContext.publicKey,
tmpCtx.publicKeyContext.address,
&global_sha3,
chainConfig->chainId);
if (!getEthAddressStringFromKey(&tmpCtx.publicKeyContext.publicKey,
tmpCtx.publicKeyContext.address,
&global_sha3,
chainConfig->chainId)) {
THROW(CX_INVALID_PARAMETER);
}
uint64_t chain_id = chainConfig->chainId;
if (dataLength >= sizeof(chain_id)) {

View File

@@ -62,10 +62,12 @@ void handlePerformPrivacyOperation(uint8_t p1,
(tmpCtx.publicKeyContext.getChaincode ? tmpCtx.publicKeyContext.chainCode : NULL));
cx_ecfp_init_private_key(CX_CURVE_256K1, privateKeyData, 32, &privateKey);
cx_ecfp_generate_pair(CX_CURVE_256K1, &tmpCtx.publicKeyContext.publicKey, &privateKey, 1);
getEthAddressStringFromKey(&tmpCtx.publicKeyContext.publicKey,
tmpCtx.publicKeyContext.address,
&global_sha3,
chainConfig->chainId);
if (!getEthAddressStringFromKey(&tmpCtx.publicKeyContext.publicKey,
tmpCtx.publicKeyContext.address,
&global_sha3,
chainConfig->chainId)) {
THROW(CX_INVALID_PARAMETER);
}
if (p2 == P2_PUBLIC_ENCRYPTION_KEY) {
decodeScalar(privateKeyData, privateKeyDataSwapped);
cx_ecfp_init_private_key(CX_CURVE_Curve25519, privateKeyDataSwapped, 32, &privateKey);

View File

@@ -198,11 +198,13 @@ static bool ui_712_format_addr(const uint8_t *const data, uint8_t length) {
return false;
}
if (ui_712_field_shown()) {
getEthDisplayableAddress((uint8_t *) data,
strings.tmp.tmp,
sizeof(strings.tmp.tmp),
&global_sha3,
chainConfig->chainId);
if (!getEthDisplayableAddress((uint8_t *) data,
strings.tmp.tmp,
sizeof(strings.tmp.tmp),
&global_sha3,
chainConfig->chainId)) {
THROW(APDU_RESPONSE_ERROR_NO_INFO);
}
}
return true;
}

View File

@@ -1,3 +1,4 @@
#include <ctype.h>
#include "shared_context.h"
#include "utils.h"
#include "feature_signTx.h"
@@ -9,7 +10,7 @@
#include "ethUtils.h"
#include "common_ui.h"
#include "ui_callbacks.h"
#include <ctype.h>
#include "apdu_constants.h"
#define ERR_SILENT_MODE_CHECK_FAILED 0x6001
@@ -189,7 +190,9 @@ static void address_to_string(uint8_t *in,
cx_sha3_t *sha3,
uint64_t chainId) {
if (in_len != 0) {
getEthDisplayableAddress(in, out, out_len, sha3, chainId);
if (!getEthDisplayableAddress(in, out, out_len, sha3, chainId)) {
THROW(APDU_RESPONSE_ERROR_NO_INFO);
}
} else {
strlcpy(out, "Contract", out_len);
}
@@ -269,7 +272,9 @@ static void get_network_as_string(char *out, size_t out_size) {
if (name == NULL) {
// No network name found so simply copy the chain ID as the network name.
u64_to_string(chain_id, out, out_size);
if (!u64_to_string(chain_id, out, out_size)) {
THROW(0x6502);
}
} else {
// Network name found, simply copy it.
strlcpy(out, name, out_size);
@@ -294,7 +299,9 @@ static void get_public_key(uint8_t *out, uint8_t outLength) {
cx_ecfp_generate_pair(CX_CURVE_256K1, &publicKey, &privateKey, 1);
explicit_bzero(&privateKey, sizeof(privateKey));
explicit_bzero(privateKeyData, sizeof(privateKeyData));
getEthAddressFromKey(&publicKey, out, &global_sha3);
if (!getEthAddressFromKey(&publicKey, out, &global_sha3)) {
THROW(CX_INVALID_PARAMETER);
}
}
/* Local implmentation of strncasecmp, workaround of the segfaulting base implem