Skip to content

Commit

Permalink
Merge pull request #53 from LedgerHQ/fix_throws
Browse files Browse the repository at this point in the history
[fix] Clear memory even on errors
  • Loading branch information
fbeutin-ledger authored Feb 7, 2023
2 parents 5301613 + fe0c28d commit 57aeca6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/signMessage.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static uint8_t set_result_sign_message() {
memcpy(G_io_apdu_buffer, signature, SIGNATURE_LENGTH);
}
CATCH_OTHER(e) {
MEMCLEAR(privateKey);
THROW(e);
}
FINALLY {
Expand Down
1 change: 1 addition & 0 deletions src/signOffchainMessage.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ static uint8_t set_result_sign_message() {
memcpy(G_io_apdu_buffer, signature, SIGNATURE_LENGTH);
}
CATCH_OTHER(e) {
MEMCLEAR(privateKey);
THROW(e);
}
FINALLY {
Expand Down
3 changes: 3 additions & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ void get_public_key(uint8_t *publicKeyArray, const uint32_t *derivationPath, siz
cx_ecfp_generate_pair(CX_CURVE_Ed25519, &publicKey, &privateKey, 1);
}
CATCH_OTHER(e) {
MEMCLEAR(privateKey);
THROW(e);
}
FINALLY {
Expand Down Expand Up @@ -55,6 +56,7 @@ void get_private_key(cx_ecfp_private_key_t *privateKey,
privateKey);
}
CATCH_OTHER(e) {
MEMCLEAR(privateKeyData);
THROW(e);
}
FINALLY {
Expand Down Expand Up @@ -84,6 +86,7 @@ void get_private_key_with_seed(cx_ecfp_private_key_t *privateKey,
privateKey);
}
CATCH_OTHER(e) {
MEMCLEAR(privateKeyData);
THROW(e);
}
FINALLY {
Expand Down

0 comments on commit 57aeca6

Please sign in to comment.