Fix all the defects identified by Clang Static Analyzer
Some fixes are dirty, but it is a start to enforce scan-build on every commit. Signed-off-by: pscott <scott.piriou@ledger.fr>
This commit is contained in:
committed by
pscott
parent
c27d59d792
commit
cd78581ffd
@@ -280,18 +280,22 @@ void starkware_print_stark_key(uint8_t *starkKey, char *destination) {
|
||||
}
|
||||
|
||||
// TODO : rewrite as independant code
|
||||
void starkware_print_eth_address(uint8_t *address, char *destination) {
|
||||
void starkware_print_eth_address(uint8_t *address, char *destination, size_t destinationLength) {
|
||||
if (destinationLength < 43) {
|
||||
strlcpy(destination, "ERROR", destinationLength);
|
||||
return;
|
||||
}
|
||||
destination[0] = '0';
|
||||
destination[1] = 'x';
|
||||
getEthAddressStringFromBinary(address,
|
||||
destination + 2,
|
||||
&global_sha3,
|
||||
chainConfig);
|
||||
getEthAddressStringFromBinary(address, destination + 2, &global_sha3, chainConfig);
|
||||
destination[42] = '\0';
|
||||
}
|
||||
|
||||
// TODO : rewrite as independant code
|
||||
void starkware_print_amount(uint8_t *amountData, char *destination, bool forEscape) {
|
||||
void starkware_print_amount(uint8_t *amountData,
|
||||
char *destination,
|
||||
size_t destinationLength,
|
||||
bool forEscape) {
|
||||
uint256_t amount, amountPre, quantum;
|
||||
uint8_t decimals;
|
||||
char *ticker = chainConfig->coinName;
|
||||
@@ -310,7 +314,7 @@ void starkware_print_amount(uint8_t *amountData, char *destination, bool forEsca
|
||||
tokenDefinition_t *token =
|
||||
&tmpCtx.transactionContext.tokens[dataContext.tokenContext.quantumIndex];
|
||||
decimals = token->decimals;
|
||||
ticker = (char *) token->ticker;
|
||||
ticker = token->ticker;
|
||||
readu256BE(amountData, &amountPre);
|
||||
}
|
||||
if (amountData != NULL) {
|
||||
@@ -318,35 +322,35 @@ void starkware_print_amount(uint8_t *amountData, char *destination, bool forEsca
|
||||
mul256(&amountPre, &quantum, &amount);
|
||||
}
|
||||
tostring256(&amount, 10, (char *) (G_io_apdu_buffer + 100), 100);
|
||||
strcpy(destination, ticker);
|
||||
strlcpy(destination, ticker, destinationLength);
|
||||
adjustDecimals((char *) (G_io_apdu_buffer + 100),
|
||||
strlen((char *) (G_io_apdu_buffer + 100)),
|
||||
destination + strlen(ticker),
|
||||
50 - strlen(ticker),
|
||||
destinationLength - strlen(ticker),
|
||||
decimals);
|
||||
}
|
||||
|
||||
// TODO : rewrite as independant code
|
||||
void starkware_print_ticker(char *destination) {
|
||||
void starkware_print_ticker(char *destination, size_t destinationLength) {
|
||||
char *ticker = chainConfig->coinName;
|
||||
|
||||
if (dataContext.tokenContext.quantumIndex != MAX_TOKEN) {
|
||||
tokenDefinition_t *token =
|
||||
&tmpCtx.transactionContext.tokens[dataContext.tokenContext.quantumIndex];
|
||||
ticker = (char *) token->ticker;
|
||||
ticker = token->ticker;
|
||||
}
|
||||
strcpy(destination, ticker);
|
||||
strlcpy(destination, ticker, destinationLength);
|
||||
}
|
||||
|
||||
// TODO : rewrite as independant code
|
||||
void starkware_print_asset_contract(char *destination) {
|
||||
void starkware_print_asset_contract(char *destination, size_t destinationLength) {
|
||||
// token has been validated to be present previously
|
||||
if (dataContext.tokenContext.quantumIndex != MAX_TOKEN) {
|
||||
tokenDefinition_t *token =
|
||||
&tmpCtx.transactionContext.tokens[dataContext.tokenContext.quantumIndex];
|
||||
starkware_print_eth_address(token->address, destination);
|
||||
starkware_print_eth_address(token->address, destination, destinationLength);
|
||||
} else {
|
||||
strcpy(destination, "UNKNOWN");
|
||||
strlcpy(destination, "UNKNOWN", destinationLength);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,10 +372,7 @@ void starkware_get_source_address(char *destination) {
|
||||
io_seproxyhal_io_heartbeat();
|
||||
destination[0] = '0';
|
||||
destination[1] = 'x';
|
||||
getEthAddressStringFromKey(&publicKey,
|
||||
destination + 2,
|
||||
&global_sha3,
|
||||
chainConfig);
|
||||
getEthAddressStringFromKey(&publicKey, destination + 2, &global_sha3, chainConfig);
|
||||
destination[42] = '\0';
|
||||
}
|
||||
|
||||
@@ -646,54 +647,55 @@ void starkware_plugin_call(int message, void *parameters) {
|
||||
PRINTF("starkware query contract id\n");
|
||||
switch (context->selectorIndex) {
|
||||
case STARKWARE_REGISTER:
|
||||
strcpy(msg->name, "Register");
|
||||
strlcpy(msg->name, "Register", msg->nameLength);
|
||||
break;
|
||||
case STARKWARE_DEPOSIT_TOKEN:
|
||||
case STARKWARE_DEPOSIT_ETH:
|
||||
case STARKWARE_DEPOSIT_NFT:
|
||||
case STARKWARE_PROXY_DEPOSIT_TOKEN:
|
||||
case STARKWARE_PROXY_DEPOSIT_ETH:
|
||||
strcpy(msg->name, "Deposit");
|
||||
strlcpy(msg->name, "Deposit", msg->nameLength);
|
||||
break;
|
||||
case STARKWARE_DEPOSIT_CANCEL:
|
||||
strcpy(msg->name, "Cancel Deposit");
|
||||
strlcpy(msg->name, "Cancel Deposit", msg->nameLength);
|
||||
break;
|
||||
case STARKWARE_DEPOSIT_RECLAIM:
|
||||
case STARKWARE_DEPOSIT_NFT_RECLAIM:
|
||||
strcpy(msg->name, "Reclaim Deposit");
|
||||
strlcpy(msg->name, "Reclaim Deposit", msg->nameLength);
|
||||
break;
|
||||
case STARKWARE_WITHDRAW:
|
||||
case STARKWARE_WITHDRAW_NFT:
|
||||
case STARKWARE_WITHDRAW_AND_MINT:
|
||||
strcpy(msg->name, "Withdrawal");
|
||||
strlcpy(msg->name, "Withdrawal", msg->nameLength);
|
||||
break;
|
||||
case STARKWARE_FULL_WITHDRAW:
|
||||
strcpy(msg->name, "Full Withdrawal");
|
||||
strlcpy(msg->name, "Full Withdrawal", msg->nameLength);
|
||||
break;
|
||||
case STARKWARE_FREEZE:
|
||||
strcpy(msg->name, "Freeze");
|
||||
strlcpy(msg->name, "Freeze", msg->nameLength);
|
||||
break;
|
||||
case STARKWARE_ESCAPE:
|
||||
strcpy(msg->name, "Escape");
|
||||
strlcpy(msg->name, "Escape", msg->nameLength);
|
||||
break;
|
||||
case STARKWARE_VERIFY_ESCAPE:
|
||||
strcpy(msg->name, "Verify Escape");
|
||||
strlcpy(msg->name, "Verify Escape", msg->nameLength);
|
||||
break;
|
||||
case STARKWARE_WITHDRAW_TO:
|
||||
case STARKWARE_WITHDRAW_NFT_TO:
|
||||
strcpy(msg->name, "Withdrawal To");
|
||||
strlcpy(msg->name, "Withdrawal To", msg->nameLength);
|
||||
break;
|
||||
case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN:
|
||||
case STARKWARE_REGISTER_AND_DEPOSIT_ETH:
|
||||
strcpy(msg->name, "Register&Deposit");
|
||||
strlcpy(msg->name, "Register&Deposit", msg->nameLength);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
strcpy(msg->version,
|
||||
is_deversify_contract(tmpContent.txContent.destination) ? "DeversiFi"
|
||||
: "Starkware");
|
||||
strlcpy(
|
||||
msg->version,
|
||||
is_deversify_contract(tmpContent.txContent.destination) ? "DeversiFi" : "Starkware",
|
||||
msg->versionLength);
|
||||
msg->result = ETH_PLUGIN_RESULT_OK;
|
||||
} break;
|
||||
|
||||
@@ -702,11 +704,13 @@ void starkware_plugin_call(int message, void *parameters) {
|
||||
starkware_parameters_t *context = (starkware_parameters_t *) msg->pluginContext;
|
||||
switch (msg->screenIndex) {
|
||||
case 0:
|
||||
strcpy(msg->title, "Contract Name");
|
||||
strlcpy(msg->title, "Contract Name", msg->titleLength);
|
||||
if (is_deversify_contract(tmpContent.txContent.destination)) {
|
||||
strcpy(msg->msg, "DeversiFi");
|
||||
strlcpy(msg->msg, "DeversiFi", msg->msgLength);
|
||||
} else {
|
||||
starkware_print_eth_address(tmpContent.txContent.destination, msg->msg);
|
||||
starkware_print_eth_address(tmpContent.txContent.destination,
|
||||
msg->msg,
|
||||
msg->msgLength);
|
||||
}
|
||||
msg->result = ETH_PLUGIN_RESULT_OK;
|
||||
break;
|
||||
@@ -715,12 +719,12 @@ void starkware_plugin_call(int message, void *parameters) {
|
||||
case STARKWARE_REGISTER:
|
||||
case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN:
|
||||
case STARKWARE_REGISTER_AND_DEPOSIT_ETH:
|
||||
strcpy(msg->title, "From ETH Address");
|
||||
starkware_print_eth_address(context->amount, msg->msg);
|
||||
strlcpy(msg->title, "From ETH Address", msg->titleLength);
|
||||
starkware_print_eth_address(context->amount, msg->msg, msg->msgLength);
|
||||
break;
|
||||
case STARKWARE_ESCAPE:
|
||||
strcpy(msg->title, "Amount");
|
||||
starkware_print_amount(context->amount, msg->msg, true);
|
||||
strlcpy(msg->title, "Amount", msg->titleLength);
|
||||
starkware_print_amount(context->amount, msg->msg, msg->msgLength, true);
|
||||
break;
|
||||
case STARKWARE_DEPOSIT_TOKEN:
|
||||
case STARKWARE_DEPOSIT_ETH:
|
||||
@@ -738,7 +742,7 @@ void starkware_plugin_call(int message, void *parameters) {
|
||||
case STARKWARE_WITHDRAW_AND_MINT:
|
||||
case STARKWARE_WITHDRAW_NFT:
|
||||
case STARKWARE_WITHDRAW_NFT_TO:
|
||||
strcpy(msg->title, "Master Account");
|
||||
strlcpy(msg->title, "Master Account", msg->titleLength);
|
||||
starkware_print_stark_key(context->starkKey, msg->msg);
|
||||
break;
|
||||
default:
|
||||
@@ -755,7 +759,7 @@ void starkware_plugin_call(int message, void *parameters) {
|
||||
case STARKWARE_ESCAPE:
|
||||
case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN:
|
||||
case STARKWARE_REGISTER_AND_DEPOSIT_ETH:
|
||||
strcpy(msg->title, "Master Account");
|
||||
strlcpy(msg->title, "Master Account", msg->titleLength);
|
||||
starkware_print_stark_key(context->starkKey, msg->msg);
|
||||
break;
|
||||
|
||||
@@ -769,22 +773,22 @@ void starkware_plugin_call(int message, void *parameters) {
|
||||
case STARKWARE_FREEZE:
|
||||
case STARKWARE_DEPOSIT_NFT:
|
||||
case STARKWARE_DEPOSIT_NFT_RECLAIM:
|
||||
strcpy(msg->title, "Token Account");
|
||||
strlcpy(msg->title, "Token Account", msg->titleLength);
|
||||
starkware_print_vault_id(U4BE(context->vaultId, 0), msg->msg);
|
||||
break;
|
||||
case STARKWARE_WITHDRAW:
|
||||
case STARKWARE_WITHDRAW_NFT:
|
||||
strcpy(msg->title, "To ETH Address");
|
||||
strlcpy(msg->title, "To ETH Address", msg->titleLength);
|
||||
starkware_get_source_address(msg->msg);
|
||||
break;
|
||||
case STARKWARE_WITHDRAW_TO:
|
||||
case STARKWARE_WITHDRAW_NFT_TO:
|
||||
strcpy(msg->title, "To ETH Address");
|
||||
starkware_print_eth_address(context->amount, msg->msg);
|
||||
strlcpy(msg->title, "To ETH Address", msg->titleLength);
|
||||
starkware_print_eth_address(context->amount, msg->msg, msg->msgLength);
|
||||
break;
|
||||
case STARKWARE_WITHDRAW_AND_MINT:
|
||||
strcpy(msg->title, "Asset Contract");
|
||||
starkware_print_asset_contract(msg->msg);
|
||||
strlcpy(msg->title, "Asset Contract", msg->titleLength);
|
||||
starkware_print_asset_contract(msg->msg, msg->msgLength);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -799,39 +803,40 @@ void starkware_plugin_call(int message, void *parameters) {
|
||||
case 3:
|
||||
switch (context->selectorIndex) {
|
||||
case STARKWARE_ESCAPE:
|
||||
strcpy(msg->title, "Token Account");
|
||||
strlcpy(msg->title, "Token Account", msg->titleLength);
|
||||
starkware_print_vault_id(U4BE(context->vaultId, 0), msg->msg);
|
||||
break;
|
||||
case STARKWARE_DEPOSIT_TOKEN:
|
||||
case STARKWARE_DEPOSIT_ETH:
|
||||
case STARKWARE_PROXY_DEPOSIT_TOKEN:
|
||||
case STARKWARE_PROXY_DEPOSIT_ETH:
|
||||
strcpy(msg->title, "Amount");
|
||||
strlcpy(msg->title, "Amount", msg->titleLength);
|
||||
starkware_print_amount(
|
||||
(((context->selectorIndex == STARKWARE_DEPOSIT_ETH) ||
|
||||
(context->selectorIndex == STARKWARE_PROXY_DEPOSIT_ETH))
|
||||
? NULL
|
||||
: context->amount),
|
||||
msg->msg,
|
||||
msg->msgLength,
|
||||
false);
|
||||
break;
|
||||
case STARKWARE_WITHDRAW:
|
||||
case STARKWARE_WITHDRAW_TO:
|
||||
strcpy(msg->title, "Token Symbol");
|
||||
starkware_print_ticker(msg->msg);
|
||||
strlcpy(msg->title, "Token Symbol", msg->titleLength);
|
||||
starkware_print_ticker(msg->msg, msg->msgLength);
|
||||
break;
|
||||
|
||||
case STARKWARE_WITHDRAW_NFT:
|
||||
case STARKWARE_WITHDRAW_NFT_TO:
|
||||
case STARKWARE_DEPOSIT_NFT:
|
||||
case STARKWARE_DEPOSIT_NFT_RECLAIM:
|
||||
strcpy(msg->title, "NFT Contract");
|
||||
starkware_print_asset_contract(msg->msg);
|
||||
strlcpy(msg->title, "NFT Contract", msg->titleLength);
|
||||
starkware_print_asset_contract(msg->msg, msg->msgLength);
|
||||
break;
|
||||
|
||||
case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN:
|
||||
case STARKWARE_REGISTER_AND_DEPOSIT_ETH:
|
||||
strcpy(msg->title, "Token Account");
|
||||
strlcpy(msg->title, "Token Account", msg->titleLength);
|
||||
starkware_print_vault_id(U4BE(context->vaultId, 0), msg->msg);
|
||||
break;
|
||||
|
||||
@@ -850,18 +855,19 @@ void starkware_plugin_call(int message, void *parameters) {
|
||||
case STARKWARE_WITHDRAW_NFT_TO:
|
||||
case STARKWARE_DEPOSIT_NFT:
|
||||
case STARKWARE_DEPOSIT_NFT_RECLAIM:
|
||||
strcpy(msg->title, "TokenID");
|
||||
strlcpy(msg->title, "TokenID", msg->titleLength);
|
||||
starkware_print_stark_key(dataContext.tokenContext.quantum, msg->msg);
|
||||
break;
|
||||
|
||||
case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN:
|
||||
case STARKWARE_REGISTER_AND_DEPOSIT_ETH:
|
||||
strcpy(msg->title, "Amount");
|
||||
strlcpy(msg->title, "Amount", msg->titleLength);
|
||||
starkware_print_amount(
|
||||
((context->selectorIndex == STARKWARE_REGISTER_AND_DEPOSIT_ETH)
|
||||
? NULL
|
||||
: context->amount),
|
||||
msg->msg,
|
||||
msg->msgLength,
|
||||
false);
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user