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

AccountInfo::assign is unsound #28607

Closed
brson opened this issue Oct 26, 2022 · 3 comments
Closed

AccountInfo::assign is unsound #28607

brson opened this issue Oct 26, 2022 · 3 comments
Assignees
Labels
community Community contribution

Comments

@brson
Copy link
Contributor

brson commented Oct 26, 2022

Problem

Here's the definition:

    pub fn assign(&self, new_owner: &Pubkey) {
        // Set the non-mut owner field
        unsafe {
            std::ptr::write_volatile(
                self.owner as *const Pubkey as *mut [u8; 32],
                new_owner.to_bytes(),
            );
        }
    }

This is not allowed in Rust and causes undefined behavior. It's not clear what write_volatile is doing here, but it's probably not what is intended.

Proposed Solution

I don't see any way to do this without changing the definition of AccountInfo.

@brson brson added the community Community contribution label Oct 26, 2022
@jackcmay
Copy link
Contributor

Right, we are not able to change AccountInfo, but is being replaced as part of the ABIv2 effort

#27384

@steveluscher
Copy link
Contributor

Can this be closed as sufficiently covered by #27384, @Lichtso?

@Lichtso
Copy link
Contributor

Lichtso commented Jan 17, 2023

yes

@Lichtso Lichtso closed this as completed Jan 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
community Community contribution
Projects
None yet
Development

No branches or pull requests

4 participants