Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

token-2022: adjust PodAccount initialized check #6953

Merged
merged 1 commit into from
Jul 1, 2024

Conversation

buffalojoec
Copy link
Contributor

Problem

The method to determine if a particular PodAccount is initialized simply checks
whether or not the state field (AccountState) is not equal to zero.

However, this means that any number besides 0 is considered to be an initialized
PodAccount. This allows arbitrary data with size 165 to be considered a valid token
account. For example, &[5; 165] registers as an initialized token account.

Summary of Changes

Adjust the is_initialized method to explicitly check the two initialized AccountState
variants, rather than != 0 .

Comment on lines +1739 to +1749
// input buffer invalid
// all 5's - not a valid `AccountState`
let mut buffer = vec![5; BASE_ACCOUNT_LENGTH];
assert_eq!(
PodStateWithExtensions::<PodAccount>::unpack(&buffer),
Err(ProgramError::UninitializedAccount)
);
assert_eq!(
PodStateWithExtensionsMut::<PodAccount>::unpack(&mut buffer),
Err(ProgramError::UninitializedAccount)
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case targets the exact problem.

@buffalojoec buffalojoec requested a review from joncinque June 30, 2024 23:15
@buffalojoec buffalojoec merged commit 8de9536 into master Jul 1, 2024
35 checks passed
@buffalojoec buffalojoec deleted the pod-account-init-check branch July 1, 2024 22:48
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 this pull request may close these issues.

2 participants