Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions runtime/src/message_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ impl PreAccount {
return Err(InstructionError::ModifiedProgramId);
}

if self.owner != post.owner
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

  • MUST [ ] needs tests for this

&& (solana_sdk::native_loader::check_id(&post.owner)
|| solana_sdk::sysvar::check_id(&post.owner))
{
return Err(InstructionError::ModifiedProgramId);
}

// An account not assigned to the program cannot have its balance decrease.
if *program_id != self.owner // line coverage used to get branch coverage
&& self.lamports > post.lamports
Expand Down
24 changes: 21 additions & 3 deletions runtime/src/system_instruction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use solana_sdk::{
account_utils::StateMut,
instruction::InstructionError,
keyed_account::{from_keyed_account, get_signers, next_keyed_account, KeyedAccount},
nonce,
native_loader, nonce,
nonce_keyed_account::NonceKeyedAccount,
process_instruction::InvokeContext,
program_utils::limited_deserialize,
Expand Down Expand Up @@ -102,8 +102,8 @@ fn assign(
return Err(InstructionError::MissingRequiredSignature);
}

// guard against sysvars being made
if sysvar::check_id(&owner) {
// guard against sysvars and native loader programs being made
if sysvar::check_id(&owner) || native_loader::check_id(&owner) {
debug!("Assign: program id {} invalid", owner);
return Err(SystemError::InvalidProgramId.into());
}
Expand Down Expand Up @@ -913,6 +913,24 @@ mod tests {
);
}

#[test]
fn test_assign_to_native_loader() {
let new_owner = native_loader::id();

let from = solana_sdk::pubkey::new_rand();
let mut from_account = Account::new(100, 0, &system_program::id());

assert_eq!(
assign(
&mut from_account,
&from.into(),
&new_owner,
&[from].iter().cloned().collect::<HashSet<_>>(),
),
Err(SystemError::InvalidProgramId.into())
);
}

#[test]
fn test_process_bogus_instruction() {
// Attempt to assign with no accounts
Expand Down