* Makes argument / parameter interfaces more clear.

* Fixes the bug in #20598
This commit is contained in:
Alexander Meißner 2021-10-14 08:47:41 +02:00 committed by GitHub
parent 588168b99d
commit bbc0bb4f02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 12 deletions

View File

@ -71,8 +71,8 @@ fn map_ebpf_error(invoke_context: &dyn InvokeContext, e: EbpfError<BpfError>) ->
} }
pub fn create_executor( pub fn create_executor(
program_account_index: usize, programdata_account_index: usize,
program_data_offset: usize, programdata_offset: usize,
invoke_context: &mut dyn InvokeContext, invoke_context: &mut dyn InvokeContext,
use_jit: bool, use_jit: bool,
) -> Result<Arc<BpfExecutor>, InstructionError> { ) -> Result<Arc<BpfExecutor>, InstructionError> {
@ -91,11 +91,9 @@ pub fn create_executor(
}; };
let mut executable = { let mut executable = {
let keyed_accounts = invoke_context.get_keyed_accounts()?; let keyed_accounts = invoke_context.get_keyed_accounts()?;
let program = keyed_account_at_index(keyed_accounts, program_account_index)?; let programdata = keyed_account_at_index(keyed_accounts, programdata_account_index)?;
let account = program.try_account_ref()?;
let data = &account.data()[program_data_offset..];
<dyn Executable<BpfError, ThisInstructionMeter>>::from_elf( <dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(
data, &programdata.try_account_ref()?.data()[programdata_offset..],
None, None,
config, config,
syscall_registry, syscall_registry,
@ -263,7 +261,7 @@ fn process_instruction_common(
Some(executor) => executor, Some(executor) => executor,
None => { None => {
let executor = create_executor( let executor = create_executor(
next_first_instruction_account, first_instruction_account,
program_data_offset, program_data_offset,
invoke_context, invoke_context,
use_jit, use_jit,
@ -349,7 +347,7 @@ fn process_loader_upgradeable_instruction(
return Err(InstructionError::InvalidAccountData); return Err(InstructionError::InvalidAccountData);
} }
write_program_data( write_program_data(
1, first_instruction_account,
UpgradeableLoaderState::buffer_data_offset()? + offset as usize, UpgradeableLoaderState::buffer_data_offset()? + offset as usize,
&bytes, &bytes,
invoke_context, invoke_context,
@ -472,7 +470,12 @@ fn process_loader_upgradeable_instruction(
)?; )?;
// Load and verify the program bits // Load and verify the program bits
let executor = create_executor(4, buffer_data_offset, invoke_context, use_jit)?; let executor = create_executor(
first_instruction_account + 3,
buffer_data_offset,
invoke_context,
use_jit,
)?;
invoke_context.add_executor(&new_program_id, executor); invoke_context.add_executor(&new_program_id, executor);
let keyed_accounts = invoke_context.get_keyed_accounts()?; let keyed_accounts = invoke_context.get_keyed_accounts()?;
@ -611,7 +614,12 @@ fn process_loader_upgradeable_instruction(
} }
// Load and verify the program bits // Load and verify the program bits
let executor = create_executor(3, buffer_data_offset, invoke_context, use_jit)?; let executor = create_executor(
first_instruction_account + 2,
buffer_data_offset,
invoke_context,
use_jit,
)?;
invoke_context.add_executor(&new_program_id, executor); invoke_context.add_executor(&new_program_id, executor);
let keyed_accounts = invoke_context.get_keyed_accounts()?; let keyed_accounts = invoke_context.get_keyed_accounts()?;
@ -878,7 +886,12 @@ fn process_loader_instruction(
ic_msg!(invoke_context, "Program account did not sign"); ic_msg!(invoke_context, "Program account did not sign");
return Err(InstructionError::MissingRequiredSignature); return Err(InstructionError::MissingRequiredSignature);
} }
write_program_data(1, offset as usize, &bytes, invoke_context)?; write_program_data(
first_instruction_account,
offset as usize,
&bytes,
invoke_context,
)?;
} }
LoaderInstruction::Finalize => { LoaderInstruction::Finalize => {
if program.signer_key().is_none() { if program.signer_key().is_none() {
@ -886,7 +899,7 @@ fn process_loader_instruction(
return Err(InstructionError::MissingRequiredSignature); return Err(InstructionError::MissingRequiredSignature);
} }
let executor = create_executor(1, 0, invoke_context, use_jit)?; let executor = create_executor(first_instruction_account, 0, invoke_context, use_jit)?;
let keyed_accounts = invoke_context.get_keyed_accounts()?; let keyed_accounts = invoke_context.get_keyed_accounts()?;
let program = keyed_account_at_index(keyed_accounts, first_instruction_account)?; let program = keyed_account_at_index(keyed_accounts, first_instruction_account)?;
invoke_context.add_executor(program.unsigned_key(), executor); invoke_context.add_executor(program.unsigned_key(), executor);