Skip to content

Commit f82f939

Browse files
committed
Update validate_owner callsite
1 parent f9354d1 commit f82f939

File tree

9 files changed

+32
-16
lines changed

9 files changed

+32
-16
lines changed

p-token/src/processor/close_account.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ pub fn process_close_account(accounts: &[AccountInfo]) -> ProgramResult {
3737
.unwrap_or(&source_account.owner);
3838

3939
if !source_account.is_owned_by_system_program_or_incinerator() {
40-
validate_owner(authority, authority_info, remaining)?;
40+
// SAFETY: `authority_info` is not currently borrowed.
41+
unsafe { validate_owner(authority, authority_info, remaining)? };
4142
} else if destination_account_info.key() != &INCINERATOR_ID {
4243
return Err(ProgramError::InvalidAccountData);
4344
}

p-token/src/processor/revoke.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ pub fn process_revoke(accounts: &[AccountInfo]) -> ProgramResult {
2828
return Err(TokenError::AccountFrozen.into());
2929
}
3030

31-
validate_owner(&source_account.owner, owner_info, remaining)?;
31+
// SAFETY: `owner_info` is not currently borrowed.
32+
unsafe { validate_owner(&source_account.owner, owner_info, remaining)? }
3233

3334
source_account.clear_delegate();
3435
source_account.set_delegated_amount(0);

p-token/src/processor/set_authority.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ pub fn process_set_authority(accounts: &[AccountInfo], instruction_data: &[u8])
5050

5151
match authority_type {
5252
AuthorityType::AccountOwner => {
53-
validate_owner(&account.owner, authority_info, remaining)?;
53+
// SAFETY: `authority_info` is not currently borrowed.
54+
unsafe { validate_owner(&account.owner, authority_info, remaining)? };
5455

5556
if let Some(authority) = new_authority {
5657
account.owner = *authority;
@@ -67,7 +68,8 @@ pub fn process_set_authority(accounts: &[AccountInfo], instruction_data: &[u8])
6768
}
6869
AuthorityType::CloseAccount => {
6970
let authority = account.close_authority().unwrap_or(&account.owner);
70-
validate_owner(authority, authority_info, remaining)?;
71+
// SAFETY: `authority_info` is not currently borrowed.
72+
unsafe { validate_owner(authority, authority_info, remaining)? };
7173

7274
if let Some(authority) = new_authority {
7375
account.set_close_authority(authority);
@@ -90,7 +92,8 @@ pub fn process_set_authority(accounts: &[AccountInfo], instruction_data: &[u8])
9092
// mint_authority.
9193
let mint_authority = mint.mint_authority().ok_or(TokenError::FixedSupply)?;
9294

93-
validate_owner(mint_authority, authority_info, remaining)?;
95+
// SAFETY: `authority_info` is not currently borrowed.
96+
unsafe { validate_owner(mint_authority, authority_info, remaining)? };
9497

9598
if let Some(authority) = new_authority {
9699
mint.set_mint_authority(authority);
@@ -105,7 +108,8 @@ pub fn process_set_authority(accounts: &[AccountInfo], instruction_data: &[u8])
105108
.freeze_authority()
106109
.ok_or(TokenError::MintCannotFreeze)?;
107110

108-
validate_owner(freeze_authority, authority_info, remaining)?;
111+
// SAFETY: `authority_info` is not currently borrowed.
112+
unsafe { validate_owner(freeze_authority, authority_info, remaining)? };
109113

110114
if let Some(authority) = new_authority {
111115
mint.set_freeze_authority(authority);

p-token/src/processor/shared/approve.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ pub fn process_approve(
6969
}
7070
}
7171

72-
validate_owner(&source_account.owner, owner_info, remaining)?;
72+
// SAFETY: `owner_info` is not currently borrowed.
73+
unsafe { validate_owner(&source_account.owner, owner_info, remaining)? };
7374

7475
// Sets the delegate and delegated amount.
7576

p-token/src/processor/shared/burn.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ pub fn process_burn(
5454
if !source_account.is_owned_by_system_program_or_incinerator() {
5555
match source_account.delegate() {
5656
Some(delegate) if authority_info.key() == delegate => {
57-
validate_owner(delegate, authority_info, remaining)?;
57+
// SAFETY: `authority_info` is not currently borrowed.
58+
unsafe { validate_owner(delegate, authority_info, remaining)? };
5859

5960
let delegated_amount = source_account
6061
.delegated_amount()
@@ -67,7 +68,8 @@ pub fn process_burn(
6768
}
6869
}
6970
_ => {
70-
validate_owner(&source_account.owner, authority_info, remaining)?;
71+
// SAFETY: `authority_info` is not currently borrowed.
72+
unsafe { validate_owner(&source_account.owner, authority_info, remaining)? };
7173
}
7274
}
7375
}

p-token/src/processor/shared/mint_to.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ pub fn process_mint_to(
4848
}
4949

5050
match mint.mint_authority() {
51-
Some(mint_authority) => validate_owner(mint_authority, owner_info, remaining)?,
51+
// SAFETY: `owner_info` is not currently borrowed.
52+
Some(mint_authority) => unsafe { validate_owner(mint_authority, owner_info, remaining)? },
5253
None => return Err(TokenError::FixedSupply.into()),
5354
}
5455

p-token/src/processor/shared/toggle_account_state.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ pub fn process_toggle_account_state(accounts: &[AccountInfo], freeze: bool) -> P
3535
let mint = unsafe { load::<Mint>(mint_info.borrow_data_unchecked())? };
3636

3737
match mint.freeze_authority() {
38-
Some(authority) => validate_owner(authority, authority_info, remaining),
38+
// SAFETY: `authority_info` is not currently borrowed.
39+
Some(authority) => unsafe { validate_owner(authority, authority_info, remaining) },
3940
None => Err(TokenError::MintCannotFreeze.into()),
4041
}?;
4142

p-token/src/processor/shared/transfer.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ pub fn process_transfer(
127127
// Validates the authority (delegate or owner).
128128

129129
if source_account.delegate() == Some(authority_info.key()) {
130-
validate_owner(authority_info.key(), authority_info, remaining)?;
130+
// SAFETY: `authority_info` is not currently borrowed.
131+
unsafe { validate_owner(authority_info.key(), authority_info, remaining)? };
131132

132133
let delegated_amount = source_account
133134
.delegated_amount()
@@ -142,7 +143,8 @@ pub fn process_transfer(
142143
}
143144
}
144145
} else {
145-
validate_owner(&source_account.owner, authority_info, remaining)?;
146+
// SAFETY: `authority_info` is not currently borrowed.
147+
unsafe { validate_owner(&source_account.owner, authority_info, remaining)? };
146148
}
147149

148150
if self_transfer || amount == 0 {

p-token/src/processor/withdraw_excess_lamports.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@ pub fn process_withdraw_excess_lamports(accounts: &[AccountInfo]) -> ProgramResu
3030
return Err(TokenError::NativeNotSupported.into());
3131
}
3232

33-
validate_owner(&account.owner, authority_info, remaining)?;
33+
// SAFETY: `authority_info` is not currently borrowed.
34+
unsafe { validate_owner(&account.owner, authority_info, remaining)? };
3435
}
3536
Mint::LEN => {
3637
// SAFETY: `source_data` has the same length as `Mint`.
3738
let mint = unsafe { load::<Mint>(source_data)? };
3839

3940
match mint.mint_authority() {
4041
Some(mint_authority) => {
41-
validate_owner(mint_authority, authority_info, remaining)?;
42+
// SAFETY: `authority_info` is not currently borrowed.
43+
unsafe { validate_owner(mint_authority, authority_info, remaining)? };
4244
}
4345
None if source_account_info == authority_info => {
4446
// Comparing whether the AccountInfo's "point" to the same account or
@@ -58,7 +60,8 @@ pub fn process_withdraw_excess_lamports(accounts: &[AccountInfo]) -> ProgramResu
5860
}
5961
}
6062
Multisig::LEN => {
61-
validate_owner(source_account_info.key(), authority_info, remaining)?;
63+
// SAFETY: `authority_info` is not currently mutably borrowed.
64+
unsafe { validate_owner(source_account_info.key(), authority_info, remaining)? };
6265
}
6366
_ => return Err(TokenError::InvalidState.into()),
6467
}

0 commit comments

Comments
 (0)