Skip to content

Commit 3de395c

Browse files
authored
lang: Check that ProgramAccount writable on deref_mut (otter-sec#681)
1 parent b977e01 commit 3de395c

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ incremented for features.
1111

1212
## [Unreleased]
1313

14+
### Features
15+
16+
* lang: Check that ProgramAccount writable before mut borrow (`anchor-debug` only) ([#681](https://github.com/project-serum/anchor/pull/681)).
17+
1418
## [0.14.0] - 2021-09-02
1519

1620
### Features

lang/src/program_account.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Clone> Deref for ProgramAcco
156156

157157
impl<'a, T: AccountSerialize + AccountDeserialize + Clone> DerefMut for ProgramAccount<'a, T> {
158158
fn deref_mut(&mut self) -> &mut Self::Target {
159+
#[cfg(feature = "anchor-debug")]
160+
if !self.inner.info.is_writable {
161+
solana_program::msg!("The given ProgramAccount is not mutable");
162+
panic!();
163+
}
164+
159165
&mut DerefMut::deref_mut(&mut self.inner).account
160166
}
161167
}

0 commit comments

Comments
 (0)