Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accounts-db: test_hash_stored_account: Reduce bool UB #33125

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12577,9 +12577,15 @@ pub mod tests {
}

//UNSAFE: forcibly cast the special byte pattern to actual account fields.
let InputFields(slot, meta, account_meta, data, offset, hash) =
let InputFields(slot, meta, mut account_meta, data, offset, hash) =
unsafe { std::mem::transmute::<InputBlob, InputFields>(blob) };

/*
* Reduce the undefined behaviour impact by overwriting a random value we assigned above
* into a `bool`.
*/
account_meta.executable = true;

// When adding a field to the following constructor, make sure this is sourced from
// InputFields as well after adding new corresponding one to it. Needless to say, but note
// that the hashing code itself must be adjusted
Expand All @@ -12593,11 +12599,8 @@ pub mod tests {
});
let account = stored_account.to_account_shared_data();

let expected_account_hash = if cfg!(debug_assertions) {
Hash::from_str("8GiQSN2VvWASKPUuZgFkH4v66ihEanrDVXAkMFvLwEa8").unwrap()
} else {
Hash::from_str("9MYASra3mm8oXzMapYUonB6TcRsKFPtjhNXVgY3MPPUX").unwrap()
};
let expected_account_hash =
Hash::from_str("9MYASra3mm8oXzMapYUonB6TcRsKFPtjhNXVgY3MPPUX").unwrap();

assert_eq!(
AccountsDb::hash_account(
Expand Down