Skip to content

Commit

Permalink
fix: address validation added (#53)
Browse files Browse the repository at this point in the history
* fix: address validation added

* style: cargo lint fixes

* style: cargo lint fixes

* fix: address validation for CallServiceMessageRequest decode added
  • Loading branch information
gcranju authored Sep 6, 2023
1 parent afae169 commit 3c05e02
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
3 changes: 2 additions & 1 deletion contracts/cosmwasm-vm/cw-xcall/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
impl<'a> CwCallService<'a> {
pub fn call_connection_send_message(
&self,
address: &str,
address: &Addr,
fee: Vec<Coin>,
to: NetId,
sn: i64,
Expand Down Expand Up @@ -71,6 +71,7 @@ impl<'a> CwCallService<'a> {
address: Addr,
) -> Result<Response, ContractError> {
self.ensure_admin(deps.storage, info.sender)?;
deps.api.addr_validate(address.as_str())?;
self.store_default_connection(deps.storage, nid, address)?;

Ok(Response::new().add_attribute("method", "set_default_connection"))
Expand Down
10 changes: 9 additions & 1 deletion contracts/cosmwasm-vm/cw-xcall/src/execute_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,15 @@ impl<'a> CwCallService<'a> {
}
submsgs = reply_address
.iter()
.map(|to| self.call_connection_send_message(to, vec![], from.nid(), sn, &message))
.map(|to| {
self.call_connection_send_message(
&deps.api.addr_validate(to)?,
vec![],
from.nid(),
sn,
&message,
)
})
.collect::<Result<Vec<SubMsg>, ContractError>>()?;
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/cosmwasm-vm/cw-xcall/src/handle_call_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<'a> CwCallService<'a> {
return Err(ContractError::ProtocolsMismatch);
}

let to = request.to();
let to = deps.api.addr_validate(request.to().as_str())?;

if request.protocols().len() > 1 {
let key = keccak256(data).to_vec();
Expand Down
11 changes: 3 additions & 8 deletions contracts/cosmwasm-vm/cw-xcall/src/send_call_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<'a> CwCallService<'a> {

let call_request = CSMessageRequest::new(
from,
to.account(),
deps.api.addr_validate(to.account().as_str())?,
sequence_no,
need_response,
data.to_vec(),
Expand All @@ -76,14 +76,9 @@ impl<'a> CwCallService<'a> {
} else {
vec![]
};
let address = deps.api.addr_validate(r)?;

self.call_connection_send_message(
&r.to_string(),
fund,
to.nid(),
sn,
&message,
)
self.call_connection_send_message(&address, fund, to.nid(), sn, &message)
});
})
.collect::<Result<Vec<SubMsg>, ContractError>>()?;
Expand Down

0 comments on commit 3c05e02

Please sign in to comment.