Skip to content

Commit d92d6f4

Browse files
authored
Audit Fixes 8 : Silent failures when unregistering non-existent sub-accounts (#552)
1 parent d64a6e8 commit d92d6f4

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

framework/contracts/account/src/error.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ pub enum AccountError {
8181
NotWhitelisted {},
8282

8383
// ** Sub Account ** //
84-
#[error("Removing sub account failed")]
85-
SubAccountRemovalFailed {},
84+
#[error("Sub account doesn't exist")]
85+
SubAccountDoesntExist {},
86+
87+
#[error("Sub account is expected to be the caller")]
88+
SubAccountIsNotCaller {},
8689

8790
#[error("Register of sub account failed")]
8891
SubAccountRegisterFailed {},

framework/contracts/account/src/sub_account.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,19 @@ fn unregister_sub_account(deps: DepsMut, env: &Env, info: MessageInfo, id: u32)
113113
&AccountId::local(id),
114114
)?;
115115

116-
if account.is_some_and(|a| a.addr() == info.sender) {
117-
SUB_ACCOUNTS.remove(deps.storage, id);
118-
119-
Ok(AccountResponse::new(
120-
"unregister_sub_account",
121-
vec![("sub_account_removed", id.to_string())],
122-
))
116+
if let Some(account) = account {
117+
if account.addr() == info.sender {
118+
SUB_ACCOUNTS.remove(deps.storage, id);
119+
120+
Ok(AccountResponse::new(
121+
"unregister_sub_account",
122+
vec![("sub_account_removed", id.to_string())],
123+
))
124+
} else {
125+
Err(AccountError::SubAccountIsNotCaller {})
126+
}
123127
} else {
124-
Err(AccountError::SubAccountRemovalFailed {})
128+
Err(AccountError::SubAccountDoesntExist {})
125129
}
126130
}
127131

0 commit comments

Comments
 (0)