replace all usage of memset(_, 0, _) with memzero

pull/25/head
Pavol Rusnak 5 years ago
parent 66a8d18348
commit 79779f4da6
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

@ -276,7 +276,7 @@ static void layoutEthereumConfirmTx(const uint8_t *to, uint32_t to_len, const ui
{
bignum256 val;
uint8_t pad_val[32];
memset(pad_val, 0, sizeof(pad_val));
memzero(pad_val, sizeof(pad_val));
memcpy(pad_val + (32 - value_len), value, value_len);
bn_read_be(pad_val, &val);
@ -377,18 +377,18 @@ static void layoutEthereumFee(const uint8_t *value, uint32_t value_len,
char tx_value[32];
char gas_value[32];
memset(pad_val, 0, sizeof(pad_val));
memzero(pad_val, sizeof(pad_val));
memcpy(pad_val + (32 - gas_price_len), gas_price, gas_price_len);
bn_read_be(pad_val, &val);
memset(pad_val, 0, sizeof(pad_val));
memzero(pad_val, sizeof(pad_val));
memcpy(pad_val + (32 - gas_limit_len), gas_limit, gas_limit_len);
bn_read_be(pad_val, &gas);
bn_multiply(&val, &gas, &secp256k1.prime);
ethereumFormatAmount(&gas, NULL, gas_value, sizeof(gas_value));
memset(pad_val, 0, sizeof(pad_val));
memzero(pad_val, sizeof(pad_val));
memcpy(pad_val + (32 - value_len), value, value_len);
bn_read_be(pad_val, &val);
@ -450,7 +450,7 @@ void ethereum_signing_init(EthereumSignTx *msg, const HDNode *node)
ethereum_signing = true;
sha3_256_Init(&keccak_ctx);
memset(&msg_tx_request, 0, sizeof(EthereumTxRequest));
memzero(&msg_tx_request, sizeof(EthereumTxRequest));
/* set fields to 0, to avoid conditions later */
if (!msg->has_value)
msg->value.size = 0;

@ -58,6 +58,7 @@
#include "messages.pb.h"
#include "stellar.h"
#include "lisk.h"
#include "memzero.h"
// message methods
@ -66,7 +67,7 @@ static uint8_t msg_resp[MSG_OUT_SIZE] __attribute__ ((aligned));
#define RESP_INIT(TYPE) \
TYPE *resp = (TYPE *) (void *) msg_resp; \
_Static_assert(sizeof(msg_resp) >= sizeof(TYPE), #TYPE " is too large"); \
memset(resp, 0, sizeof(TYPE));
memzero(resp, sizeof(TYPE));
#define CHECK_INITIALIZED \
if (!storage_isInitialized()) { \

@ -26,7 +26,7 @@ void fsm_msgDebugLinkGetState(const DebugLinkGetState *msg)
// Do not use RESP_INIT because it clears msg_resp, but another message
// might be being handled
DebugLinkState resp;
memset(&resp, 0, sizeof(resp));
memzero(&resp, sizeof(resp));
resp.has_layout = true;
resp.layout.size = OLED_BUFSIZE;

@ -33,6 +33,7 @@
#include "secp256k1.h"
#include "nem2.h"
#include "gettext.h"
#include "memzero.h"
#define BITCOIN_DIVISIBILITY (8)
@ -98,7 +99,7 @@ static const char *address_n_str(const uint32_t *address_n, size_t address_n_cou
}
const uint32_t accnum = address_is_account ? ((address_n[4] & 0x7fffffff) + 1) : (address_n[2] & 0x7fffffff) + 1;
if (abbr && accnum < 100) {
memset(path, 0, sizeof(path));
memzero(path, sizeof(path));
strlcpy(path, abbr, sizeof(path));
// TODO: how to name accounts?
// currently we have "legacy account", "account" and "segwit account"
@ -115,7 +116,7 @@ static const char *address_n_str(const uint32_t *address_n, size_t address_n_cou
strlcat(path, " account #", sizeof(path));
}
char acc[3];
memset(acc, 0, sizeof(acc));
memzero(acc, sizeof(acc));
if (accnum < 10) {
acc[0] = '0' + accnum;
} else {
@ -163,7 +164,7 @@ const char **split_message(const uint8_t *msg, uint32_t len, uint32_t rowlen)
if (rowlen > 32) {
rowlen = 32;
}
memset(str, 0, sizeof(str));
memzero(str, sizeof(str));
strlcpy(str[0], (char *)msg, rowlen + 1);
if (len > rowlen) {
strlcpy(str[1], (char *)msg + rowlen, rowlen + 1);
@ -186,7 +187,7 @@ const char **split_message(const uint8_t *msg, uint32_t len, uint32_t rowlen)
const char **split_message_hex(const uint8_t *msg, uint32_t len)
{
char hex[32 * 2 + 1];
memset(hex, 0, sizeof(hex));
memzero(hex, sizeof(hex));
uint32_t size = len;
if (len > 32) {
size = 32;

@ -25,6 +25,7 @@
#include "fsm.h"
#include "util.h"
#include "gettext.h"
#include "memzero.h"
#include "pb_decode.h"
#include "pb_encode.h"
@ -220,7 +221,7 @@ enum {
void msg_process(char type, uint16_t msg_id, const pb_field_t *fields, uint8_t *msg_raw, uint32_t msg_size)
{
static CONFIDENTIAL uint8_t msg_data[MSG_IN_SIZE];
memset(msg_data, 0, sizeof(msg_data));
memzero(msg_data, sizeof(msg_data));
pb_istream_t stream = pb_istream_from_buffer(msg_raw, msg_size);
bool status = pb_decode(&stream, fields, msg_data);
if (status) {

@ -26,6 +26,7 @@
#include "protect.h"
#include "rng.h"
#include "secp256k1.h"
#include "memzero.h"
const char *nem_validate_common(NEMTransactionCommon *common, bool inner) {
if (!common->has_network) {
@ -733,7 +734,7 @@ size_t nem_canonicalizeMosaics(NEMMosaic *mosaics, size_t mosaics_count) {
size_t actual_count = 0;
bool skip[mosaics_count];
memset(skip, 0, sizeof(skip));
memzero(skip, sizeof(skip));
// Merge duplicates
for (size_t i = 0; i < mosaics_count; i++) {

@ -47,7 +47,7 @@ bool protectButton(ButtonRequestType type, bool confirm_only)
bool debug_decided = false;
#endif
memset(&resp, 0, sizeof(ButtonRequest));
memzero(&resp, sizeof(ButtonRequest));
resp.has_code = true;
resp.code = type;
usbTiny(1);
@ -114,7 +114,7 @@ bool protectButton(ButtonRequestType type, bool confirm_only)
const char *requestPin(PinMatrixRequestType type, const char *text)
{
PinMatrixRequest resp;
memset(&resp, 0, sizeof(PinMatrixRequest));
memzero(&resp, sizeof(PinMatrixRequest));
resp.has_type = true;
resp.type = type;
usbTiny(1);
@ -247,7 +247,7 @@ bool protectPassphrase(void)
}
PassphraseRequest resp;
memset(&resp, 0, sizeof(PassphraseRequest));
memzero(&resp, sizeof(PassphraseRequest));
usbTiny(1);
msg_write(MessageType_MessageType_PassphraseRequest, &resp);

@ -141,7 +141,7 @@ static void format_number(char *dest, int number) {
*/
static void recovery_request(void) {
WordRequest resp;
memset(&resp, 0, sizeof(WordRequest));
memzero(&resp, sizeof(WordRequest));
resp.has_type = true;
resp.type = awaiting_word == 1 ? WordRequestType_WordRequestType_Plain
: (word_index % 4 == 3) ? WordRequestType_WordRequestType_Matrix6

@ -29,6 +29,7 @@
#include "util.h"
#include "gettext.h"
#include "messages.pb.h"
#include "memzero.h"
static uint32_t strength;
static uint8_t int_entropy[32];
@ -87,7 +88,7 @@ void reset_init(bool display_random, uint32_t _strength, bool passphrase_protect
storage_update();
EntropyRequest resp;
memset(&resp, 0, sizeof(EntropyRequest));
memzero(&resp, sizeof(EntropyRequest));
msg_write(MessageType_MessageType_EntropyRequest, &resp);
awaiting_entropy = true;
}
@ -109,7 +110,7 @@ void reset_entropy(const uint8_t *ext_entropy, uint32_t len)
storage_setNeedsBackup(true);
}
storage_setMnemonic(mnemonic_from_data(int_entropy, strength / 8));
memset(int_entropy, 0, 32);
memzero(int_entropy, 32);
awaiting_entropy = false;
if (skip_backup || no_backup) {

@ -500,8 +500,8 @@ void signing_init(const SignTx *msg, const CoinInfo *_coin, const HDNode *_root)
spending = 0;
change_spend = 0;
authorized_amount = 0;
memset(&input, 0, sizeof(TxInputType));
memset(&resp, 0, sizeof(TxRequest));
memzero(&input, sizeof(TxInputType));
memzero(&resp, sizeof(TxRequest));
signing = true;
progress = 0;
@ -978,7 +978,7 @@ void signing_txack(TransactionType *tx)
update_ctr = 0;
}
memset(&resp, 0, sizeof(TxRequest));
memzero(&resp, sizeof(TxRequest));
switch (signing_stage) {
case STAGE_REQUEST_1_INPUT:

@ -54,7 +54,7 @@ static StellarTransaction stellar_activeTx;
*/
bool stellar_signingInit(const StellarSignTx *msg)
{
memset(&stellar_activeTx, 0, sizeof(StellarTransaction));
memzero(&stellar_activeTx, sizeof(StellarTransaction));
stellar_signing = true;
// Initialize signing context
sha256_Init(&(stellar_activeTx.sha256_ctx));
@ -267,7 +267,7 @@ bool stellar_confirmPaymentOp(const StellarPaymentOp *msg)
strlcat(str_to, str_addr_rows[0], sizeof(str_to));
char str_asset_row[32];
memset(str_asset_row, 0, sizeof(str_asset_row));
memzero(str_asset_row, sizeof(str_asset_row));
stellar_format_asset(&(msg->asset), str_asset_row, sizeof(str_asset_row));
char str_pay_amount[32];
@ -585,7 +585,7 @@ bool stellar_confirmSetOptionsOp(const StellarSetOptionsOp *msg)
char str_title[32];
char rows[4][32];
int row_idx = 0;
memset(rows, 0, sizeof(rows));
memzero(rows, sizeof(rows));
// Inflation destination
stellar_hashupdate_bool(msg->has_inflation_destination_account);
@ -643,7 +643,7 @@ bool stellar_confirmSetOptionsOp(const StellarSetOptionsOp *msg)
stellar_signingAbort(_("User canceled"));
return false;
}
memset(rows, 0, sizeof(rows));
memzero(rows, sizeof(rows));
row_idx = 0;
// Hash flags
@ -677,7 +677,7 @@ bool stellar_confirmSetOptionsOp(const StellarSetOptionsOp *msg)
stellar_signingAbort(_("User canceled"));
return false;
}
memset(rows, 0, sizeof(rows));
memzero(rows, sizeof(rows));
row_idx = 0;
// Hash flags
@ -750,7 +750,7 @@ bool stellar_confirmSetOptionsOp(const StellarSetOptionsOp *msg)
stellar_signingAbort(_("User canceled"));
return false;
}
memset(rows, 0, sizeof(rows));
memzero(rows, sizeof(rows));
row_idx = 0;
}
@ -780,7 +780,7 @@ bool stellar_confirmSetOptionsOp(const StellarSetOptionsOp *msg)
stellar_signingAbort(_("User canceled"));
return false;
}
memset(rows, 0, sizeof(rows));
memzero(rows, sizeof(rows));
row_idx = 0;
stellar_hashupdate_string((unsigned char*)&(msg->home_domain), strnlen(msg->home_domain, 32));
@ -876,7 +876,7 @@ bool stellar_confirmSetOptionsOp(const StellarSetOptionsOp *msg)
stellar_signingAbort(_("User canceled"));
return false;
}
memset(rows, 0, sizeof(rows));
memzero(rows, sizeof(rows));
row_idx = 0;
}
@ -1019,13 +1019,13 @@ bool stellar_confirmAllowTrustOp(const StellarAllowTrustOp *msg)
// asset code
if (msg->asset_type == 1) {
char code4[4+1];
memset(code4, 0, sizeof(code4));
memzero(code4, sizeof(code4));
strlcpy(code4, msg->asset_code, sizeof(code4));
stellar_hashupdate_bytes((uint8_t *)code4, 4);
}
if (msg->asset_type == 2) {
char code12[12+1];
memset(code12, 0, sizeof(code12));
memzero(code12, sizeof(code12));
strlcpy(code12, msg->asset_code, sizeof(code12));
stellar_hashupdate_bytes((uint8_t *)code12, 12);
}
@ -1233,7 +1233,7 @@ void stellar_getSignatureForActiveTx(uint8_t *out_signature)
const HDNode *node = stellar_deriveNode(stellar_activeTx.address_n, stellar_activeTx.address_n_count);
if (!node) {
// return empty signature when we can't derive node
memset(out_signature, 0, 64);
memzero(out_signature, 64);
return;
}
@ -1271,7 +1271,7 @@ void stellar_format_stroops(uint64_t number, char *out, size_t outlen)
*/
void stellar_format_price(uint32_t numerator, uint32_t denominator, char *out, size_t outlen)
{
memset(out, 0, outlen);
memzero(out, outlen);
// early exit for invalid denominator
if (denominator == 0) {
@ -1328,7 +1328,7 @@ const char **stellar_lineBreakAddress(const uint8_t *addrbytes)
char str_fulladdr[56+1];
static char rows[3][20+1];
memset(rows, 0, sizeof(rows));
memzero(rows, sizeof(rows));
// get full address string
stellar_publicAddressAsStr(addrbytes, str_fulladdr, sizeof(str_fulladdr));
@ -1356,9 +1356,9 @@ void stellar_format_asset(const StellarAssetType *asset, char *str_formatted, si
// truncated asset issuer, final length depends on length of asset code
char str_asset_issuer_trunc[13 + 1];
memset(str_formatted, 0, len);
memset(str_asset_code, 0, sizeof(str_asset_code));
memset(str_asset_issuer_trunc, 0, sizeof(str_asset_issuer_trunc));
memzero(str_formatted, len);
memzero(str_asset_code, sizeof(str_asset_code));
memzero(str_asset_issuer_trunc, sizeof(str_asset_issuer_trunc));
// Validate issuer account for non-native assets
if (asset->type != 0 && !stellar_validateAddress(asset->issuer)) {
@ -1621,8 +1621,8 @@ void stellar_hashupdate_asset(const StellarAssetType *asset)
// 4-character asset code
if (asset->type == 1) {
char code4[4+1];
memset(code4, 0, sizeof(code4));
char code4[4 + 1];
memzero(code4, sizeof(code4));
strlcpy(code4, asset->code, sizeof(code4));
stellar_hashupdate_bytes((uint8_t *)code4, 4);
@ -1631,8 +1631,8 @@ void stellar_hashupdate_asset(const StellarAssetType *asset)
// 12-character asset code
if (asset->type == 2) {
char code12[12+1];
memset(code12, 0, sizeof(code12));
char code12[12 + 1];
memzero(code12, sizeof(code12));
strlcpy(code12, asset->code, sizeof(code12));
stellar_hashupdate_bytes((uint8_t *)code12, 12);
@ -1651,7 +1651,7 @@ void stellar_hashupdate_bytes(const uint8_t *data, size_t len)
void stellar_layoutTransactionSummary(const StellarSignTx *msg)
{
char str_lines[5][32];
memset(str_lines, 0, sizeof(str_lines));
memzero(str_lines, sizeof(str_lines));
char str_fee[12];
char str_num_ops[12];
@ -1693,7 +1693,7 @@ void stellar_layoutTransactionSummary(const StellarSignTx *msg)
}
// Reset lines for displaying memo
memset(str_lines, 0, sizeof(str_lines));
memzero(str_lines, sizeof(str_lines));
// Memo: none
if (msg->memo_type == 0) {
@ -1747,7 +1747,7 @@ void stellar_layoutTransactionSummary(const StellarSignTx *msg)
}
// Verify timebounds, if present
memset(str_lines, 0, sizeof(str_lines));
memzero(str_lines, sizeof(str_lines));
// Timebound: lower
if (msg->timebounds_start || msg->timebounds_end) {
@ -1767,7 +1767,7 @@ void stellar_layoutTransactionSummary(const StellarSignTx *msg)
}
// Reset for timebound_max
memset(str_timebound, 0, sizeof(str_timebound));
memzero(str_timebound, sizeof(str_timebound));
timebound = (time_t)msg->timebounds_end;
strlcpy(str_lines[0], _("Valid from:"), sizeof(str_lines[0]));
@ -1817,22 +1817,22 @@ void stellar_layoutSigningDialog(const char *line1, const char *line2, const cha
}
char str_pubaddr_truncated[12]; // G???? + null
memset(str_pubaddr_truncated, 0, sizeof(str_pubaddr_truncated));
memzero(str_pubaddr_truncated, sizeof(str_pubaddr_truncated));
layoutLast = layoutDialogSwipe;
layoutSwipe();
oledClear();
// Load up public address
char str_pubaddr[56+1];
memset(str_pubaddr, 0, sizeof(str_pubaddr));
char str_pubaddr[56 + 1];
memzero(str_pubaddr, sizeof(str_pubaddr));
stellar_publicAddressAsStr(node->public_key + 1, str_pubaddr, sizeof(str_pubaddr));
memcpy(str_pubaddr_truncated, str_pubaddr, sizeof(str_pubaddr_truncated) - 1);
// Header
// Ends up as: Signing with GABCDEFGHIJKL
char str_header[32];
memset(str_header, 0, sizeof(str_header));
memzero(str_header, sizeof(str_header));
strlcpy(str_header, _("Signing with "), sizeof(str_header));
strlcat(str_header, str_pubaddr_truncated, sizeof(str_header));
@ -1896,7 +1896,7 @@ void stellar_layoutSigningDialog(const char *line1, const char *line2, const cha
void stellar_layoutTransactionDialog(const char *line1, const char *line2, const char *line3, const char *line4, const char *line5)
{
char str_warning[16];
memset(str_warning, 0, sizeof(str_warning));
memzero(str_warning, sizeof(str_warning));
if (stellar_activeTx.network_type == 2) {
// Warning: testnet

@ -446,13 +446,13 @@ void storage_loadDevice(const LoadDevice *msg)
storageUpdate.has_mnemonic = false;
storage_setNode(&(msg->node));
sessionSeedCached = false;
memset(&sessionSeed, 0, sizeof(sessionSeed));
memzero(&sessionSeed, sizeof(sessionSeed));
} else if (msg->has_mnemonic) {
storageUpdate.has_mnemonic = true;
storageUpdate.has_node = false;
strlcpy(storageUpdate.mnemonic, msg->mnemonic, sizeof(storageUpdate.mnemonic));
sessionSeedCached = false;
memset(&sessionSeed, 0, sizeof(sessionSeed));
memzero(&sessionSeed, sizeof(sessionSeed));
}
if (msg->has_language) {
@ -508,7 +508,7 @@ void storage_setHomescreen(const uint8_t *data, uint32_t size)
memcpy(storageUpdate.homescreen.bytes, data, size);
storageUpdate.homescreen.size = size;
} else {
memset(storageUpdate.homescreen.bytes, 0, sizeof(storageUpdate.homescreen.bytes));
memzero(storageUpdate.homescreen.bytes, sizeof(storageUpdate.homescreen.bytes));
storageUpdate.homescreen.size = 0;
}
}

@ -32,6 +32,7 @@
#include "messages.pb.h"
#include "segwit_addr.h"
#include "cash_addr.h"
#include "memzero.h"
#define SEGWIT_VERSION_0 0
@ -188,7 +189,7 @@ bool compute_address(const CoinInfo *coin,
int compile_output(const CoinInfo *coin, const HDNode *root, TxOutputType *in, TxOutputBinType *out, bool needs_confirm)
{
memset(out, 0, sizeof(TxOutputBinType));
memzero(out, sizeof(TxOutputBinType));
out->amount = in->amount;
out->decred_script_version = in->decred_script_version;
uint8_t addr_raw[MAX_ADDR_RAW_SIZE];
@ -623,7 +624,7 @@ uint32_t tx_serialize_footer(TxStruct *tx, uint8_t *out)
} else
if (tx->version == 4) {
memcpy(out + 4, &(tx->expiry), 4);
memset(out + 8, 0, 8); // valueBalance
memzero(out + 8, 8); // valueBalance
out[16] = 0x00; // nShieldedSpend
out[17] = 0x00; // nShieldedOutput
out[18] = 0x00; // nJoinSplit

@ -33,6 +33,7 @@
#include "hmac.h"
#include "util.h"
#include "gettext.h"
#include "memzero.h"
#include "u2f/u2f.h"
#include "u2f/u2f_hid.h"
@ -276,7 +277,7 @@ void u2fhid_wink(const uint8_t *buf, uint32_t len)
dialog_timeout = U2F_TIMEOUT;
U2FHID_FRAME f;
memset(&f, 0, sizeof(f));
memzero(&f, sizeof(f));
f.cid = cid;
f.init.cmd = U2FHID_WINK;
f.init.bcntl = 0;
@ -288,8 +289,7 @@ void u2fhid_init(const U2FHID_FRAME *in)
const U2FHID_INIT_REQ *init_req = (const U2FHID_INIT_REQ *)&in->init.data;
U2FHID_FRAME f;
U2FHID_INIT_RESP resp;
memset(&resp, 0, sizeof(resp));
memzero(&resp, sizeof(resp));
debugLog(0, "", "u2fhid_init");
@ -298,7 +298,7 @@ void u2fhid_init(const U2FHID_FRAME *in)
return;
}
memset(&f, 0, sizeof(f));
memzero(&f, sizeof(f));
f.cid = in->cid;
f.init.cmd = U2FHID_INIT;
f.init.bcnth = 0;
@ -383,7 +383,7 @@ void send_u2fhid_msg(const uint8_t cmd, const uint8_t *data, const uint32_t len)
// debugLog(0, "", "send_u2fhid_msg");
memset(&f, 0, sizeof(f));
memzero(&f, sizeof(f));
f.cid = cid;
f.init.cmd = cmd;
f.init.bcnth = len >> 8;
@ -399,7 +399,7 @@ void send_u2fhid_msg(const uint8_t cmd, const uint8_t *data, const uint32_t len)
// Cont packet(s)
for (; l > 0; l -= psz, p += psz) {
// debugLog(0, "", "send_u2fhid_msg con");
memset(&f.cont.data, 0, sizeof(f.cont.data));
memzero(&f.cont.data, sizeof(f.cont.data));
f.cont.seq = seq++;
psz = MIN(sizeof(f.cont.data), l);
memcpy(f.cont.data, p, psz);
@ -416,7 +416,7 @@ void send_u2fhid_error(uint32_t fcid, uint8_t err)
{
U2FHID_FRAME f;
memset(&f, 0, sizeof(f));
memzero(&f, sizeof(f));
f.cid = fcid;
f.init.cmd = U2FHID_ERROR;
f.init.bcntl = 1;
@ -592,7 +592,7 @@ void u2f_register(const APDU *a)
if (last_req_state == REG_PASS) {
uint8_t data[sizeof(U2F_REGISTER_RESP) + 2];
U2F_REGISTER_RESP *resp = (U2F_REGISTER_RESP *)&data;
memset(data, 0, sizeof(data));
memzero(data, sizeof(data));
resp->registerId = U2F_REGISTER_ID;
resp->keyHandleLen = KEY_HANDLE_LEN;

@ -24,6 +24,7 @@
#include "oled.h"
#include "util.h"
#include "memzero.h"
#define OLED_SETCONTRAST 0x81
#define OLED_DISPLAYALLON_RESUME 0xA4
@ -177,7 +178,7 @@ void oledInit()
*/
void oledClear()
{
memset(_oledbuffer, 0, sizeof(_oledbuffer));
memzero(_oledbuffer, sizeof(_oledbuffer));
}
void oledInvertDebugLink()

@ -1 +1 @@
Subproject commit c5227fdb969520de41664bfa4b66e74e718d72c4
Subproject commit c316e775a2152db255ace96b6b65ac0f20525ec0
Loading…
Cancel
Save