Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Undefined behavior in program spoof tests #34687

Closed
brooksprumo opened this issue Jan 8, 2024 · 1 comment · Fixed by #34706
Closed

Undefined behavior in program spoof tests #34687

brooksprumo opened this issue Jan 8, 2024 · 1 comment · Fixed by #34706

Comments

@brooksprumo
Copy link
Contributor

Problem

When upgrading nightly Rust1, a new build error2 surfaced:

error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
  --> rust/spoof1/src/lib.rs:27:9
   |
27 |         std::ptr::write_volatile(owner_addr as *mut [u8; 32], fake_system.owner.to_bytes());
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
   = note: `#[deny(invalid_reference_casting)]` on by default
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
  --> rust/spoof1/src/lib.rs:49:9
   |
49 |         std::ptr::write_volatile(owner_addr as *mut [u8; 32], tmp_native_owner);
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
error: could not compile `solana-sbf-rust-spoof1` (lib) due to 2 previous errors

When looking at the original PR that added the spoof tests3, it was unclear to me what the original intent of the tests was, and thus unclear what the obvious fix should be.

Proposed Solution

Fix the undefined behavior.

Footnotes

  1. https://github.com/solana-labs/solana/pull/34673

  2. https://buildkite.com/solana-labs/solana/builds/106384#018ce951-65cf-43cf-b89d-ab17ff8a3618

  3. https://github.com/solana-labs/solana/pull/13866

@brooksprumo
Copy link
Contributor Author

@alessandrod Is this another one I can send your way?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant