Skip to content

Commit

Permalink
[Sec]: Do not zeroize an empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
satoshiotomakan committed Oct 25, 2023
1 parent 9959935 commit 95742cb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Keystore/StoredKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ StoredKey StoredKey::createWithMnemonic(const std::string& name, const Data& pas

Data mnemonicData = TW::Data(mnemonic.begin(), mnemonic.end());
StoredKey key(StoredKeyType::mnemonicPhrase, name, password, mnemonicData, encryptionLevel, encryption);
memzero(mnemonicData.data(), mnemonic.size());
if (!mnemonicData.empty()) {
memzero(mnemonicData.data(), mnemonic.size());
}
return key;
}

Expand Down
4 changes: 3 additions & 1 deletion src/interface/TWString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ void TWStringDelete(TWString *_Nonnull string) {
// `const_cast` is safe here despite that the pointer to the string is const
// but `std::string` is not a constant value.
auto *s = const_cast<std::string*>(sConst);
memzero(s->data(), s->size());
if (!s->empty()) {
memzero(s->data(), s->size());
}
delete s;
}

Expand Down

0 comments on commit 95742cb

Please sign in to comment.