Use strlcpy instead of strncpy

This commit is contained in:
pscott
2021-07-27 12:23:55 +02:00
parent b7110eafe0
commit ee4a865144
4 changed files with 5 additions and 5 deletions

View File

@@ -10,7 +10,7 @@ bool copy_transaction_parameters(create_transaction_parameters_t* sign_transacti
// We need this "trick" as the input data position can overlap with app-ethereum globals
txStringProperties_t stack_data;
memset(&stack_data, 0, sizeof(stack_data));
strncpy(stack_data.fullAddress,
strlcpy(stack_data.fullAddress,
sign_transaction_params->destination_address,
sizeof(stack_data.fullAddress));
if ((stack_data.fullAddress[sizeof(stack_data.fullAddress) - 1] != '\0') ||

View File

@@ -93,7 +93,7 @@ bool uint256_to_decimal(const uint8_t *value, size_t value_len, char *out, size_
// Not enough space to hold "0" and \0.
return false;
}
strncpy(out, "0", out_len);
strlcpy(out, "0", out_len);
return true;
}

View File

@@ -416,7 +416,7 @@ void finalizeParsing(bool direct) {
tmpContent.txContent.nonce.length,
&nonce);
tostring256(&nonce, 10, displayBuffer, sizeof(displayBuffer));
strncpy(strings.common.nonce, displayBuffer, sizeof(strings.common.nonce));
strlcpy(strings.common.nonce, displayBuffer, sizeof(strings.common.nonce));
}
// Compute maximum fee
if (genericUI) {
@@ -444,7 +444,7 @@ void finalizeParsing(bool direct) {
}
} else {
// Network name found, simply copy it.
strncpy(strings.common.network_name, name, sizeof(strings.common.network_name));
strlcpy(strings.common.network_name, name, sizeof(strings.common.network_name));
}
}

View File

@@ -66,7 +66,7 @@ bool check_contract(erc20_parameters_t *context) {
for (size_t i = 0; i < NUM_CONTRACTS; i++) {
contract_t *contract = (contract_t *) PIC(&CONTRACTS[i]);
if (memcmp(contract->address, context->destinationAddress, ADDRESS_LENGTH) == 0) {
strncpy(context->contract_name, contract->name, sizeof(context->contract_name));
strlcpy(context->contract_name, contract->name, sizeof(context->contract_name));
return true;
}
}