Skip to content

Commit

Permalink
#48 Fix Audit Issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mich-master committed Jun 13, 2022
1 parent e8ed6e5 commit 30bfdd6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
3 changes: 3 additions & 0 deletions maintenance/program/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ pub enum MaintenanceError {
/// Wrong Authority
#[error("Wrong Authority")]
WrongAuthority,
/// Incorrect Bpf-Loader-Upgradeable Program Id
#[error("Incorrect Bpf-Loader-Upgradeable Program Id")]
IncorrectBpfLoaderProgramId,
/// Buffer Data Offset Error
#[error("Buffer Data Offset Error")]
BufferDataOffsetError,
Expand Down
10 changes: 6 additions & 4 deletions maintenance/program/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ pub enum MaintenanceInstruction {

/// Closes MaintenanceRecord owned by the program
///
/// 0. `[writable]` MaintenanceRecord
/// 1. `[]` Maintained program data account
/// 2. `[signer]` Authority
/// 3. `[writable]` Spill destination
/// 0. `[]` Bpf Loader Upgradeable Program Id
/// 1. `[writable]` MaintenanceRecord
/// 2. `[]` Maintained program account
/// 3. `[]` Maintained program data account
/// 4. `[signer]` Authority
/// 5. `[writable]` Spill destination
CloseMaintenance { },
}

Expand Down
9 changes: 7 additions & 2 deletions maintenance/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use borsh::{ BorshDeserialize, BorshSerialize };
use solana_program::{
account_info::{next_account_info, AccountInfo},
bpf_loader_upgradeable::{
self,
set_upgrade_authority,
upgrade,
UpgradeableLoaderState,
Expand Down Expand Up @@ -92,7 +93,7 @@ pub fn process_create_maintenance(

let maintenance_record_data = MaintenanceRecord {
account_type: MaintenanceAccountType::MaintenanceRecord,
address: *address_info.key,
maintained_address: *address_info.key,
authority: *authority_info.key,
delegate: Vec::new(),
hashes: Vec::new(),
Expand Down Expand Up @@ -321,6 +322,10 @@ pub fn process_close_maintenance(
return Err(MaintenanceError::MissingRequiredSigner.into());
}

if !bpf_loader_upgradeable::check_id(bpf_loader_program_info.key) {
return Err(MaintenanceError::IncorrectBpfLoaderProgramId.into());
}

if maintenance_record_info.key == spill_info.key {
return Err(MaintenanceError::MaintenanceRecordAccountMatchesSpillAccount.into());
}
Expand All @@ -329,7 +334,7 @@ pub fn process_close_maintenance(
let maintenance_record = get_account_data::<MaintenanceRecord>(program_id, maintenance_record_info)?;

if *maintained_program_data_info.key != maintained_program_data ||
*maintained_program_info.key != maintenance_record.address {
*maintained_program_info.key != maintenance_record.maintained_address {
return Err(MaintenanceError::WrongProgramDataForMaintenanceRecord.into());
}

Expand Down
4 changes: 2 additions & 2 deletions maintenance/program/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub enum MaintenanceAccountType {
#[derive(Clone, Debug, PartialEq, BorshDeserialize, BorshSerialize, BorshSchema)]
pub struct MaintenanceRecord {
pub account_type: MaintenanceAccountType,
pub address: Pubkey,
pub maintained_address: Pubkey,
pub authority: Pubkey,
pub delegate: Vec<Pubkey>,
pub hashes: Vec<Hash>,
Expand Down Expand Up @@ -49,7 +49,7 @@ mod tests {
fn test_maintenance_record_packing() {
let maintenance_record_source = MaintenanceRecord {
account_type: MaintenanceAccountType::MaintenanceRecord,
address: Pubkey::new_unique(),
maintained_address: Pubkey::new_unique(),
authority: Pubkey::new_unique(),
delegate: Vec::new(),
hashes: Vec::new(),
Expand Down

0 comments on commit 30bfdd6

Please sign in to comment.