Check native account owner (#14535)

(cherry picked from commit 8ad5931bfc)
This commit is contained in:
Jack May
2021-01-11 14:36:52 -08:00
committed by Michael Vines
parent 4440a8d9fa
commit 25fe93e9fb
2 changed files with 12 additions and 2 deletions

View File

@ -487,7 +487,7 @@ impl MessageProcessor {
} }
// Call the program via the native loader // Call the program via the native loader
return self.native_loader.process_instruction( return self.native_loader.process_instruction(
program_id, &native_loader::id(),
keyed_accounts, keyed_accounts,
instruction_data, instruction_data,
invoke_context, invoke_context,

View File

@ -10,6 +10,7 @@ use solana_sdk::{
entrypoint_native::ProgramEntrypoint, entrypoint_native::ProgramEntrypoint,
instruction::InstructionError, instruction::InstructionError,
keyed_account::{next_keyed_account, KeyedAccount}, keyed_account::{next_keyed_account, KeyedAccount},
native_loader,
process_instruction::{InvokeContext, LoaderEntrypoint}, process_instruction::{InvokeContext, LoaderEntrypoint},
pubkey::Pubkey, pubkey::Pubkey,
}; };
@ -126,13 +127,22 @@ impl NativeLoader {
pub fn process_instruction( pub fn process_instruction(
&self, &self,
_program_id: &Pubkey, program_id: &Pubkey,
keyed_accounts: &[KeyedAccount], keyed_accounts: &[KeyedAccount],
instruction_data: &[u8], instruction_data: &[u8],
invoke_context: &dyn InvokeContext, invoke_context: &dyn InvokeContext,
) -> Result<(), InstructionError> { ) -> Result<(), InstructionError> {
let mut keyed_accounts_iter = keyed_accounts.iter(); let mut keyed_accounts_iter = keyed_accounts.iter();
let program = next_keyed_account(&mut keyed_accounts_iter)?; let program = next_keyed_account(&mut keyed_accounts_iter)?;
if native_loader::id() != *program_id {
error!("Program id mismatch");
return Err(InstructionError::IncorrectProgramId);
}
if program.owner()? != *program_id {
error!("Executable account now owned by loader");
return Err(InstructionError::IncorrectProgramId);
}
let params = keyed_accounts_iter.as_slice(); let params = keyed_accounts_iter.as_slice();
let name_vec = &program.try_account_ref()?.data; let name_vec = &program.try_account_ref()?.data;
let name = match str::from_utf8(name_vec) { let name = match str::from_utf8(name_vec) {