Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lang: check that ProgramAccount writable on deref_mut #681

Merged
merged 2 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ incremented for features.

## [Unreleased]

### Features

* lang: Check that ProgramAccount writable before mut borrow ([#681](https://github.com/project-serum/anchor/pull/681)).

## [0.14.0] - 2021-09-02

### Features
Expand Down
6 changes: 6 additions & 0 deletions lang/src/program_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
use solana_program::account_info::AccountInfo;
use solana_program::entrypoint::ProgramResult;
use solana_program::instruction::AccountMeta;
use solana_program::msg;
use solana_program::program_error::ProgramError;
use solana_program::pubkey::Pubkey;
use std::ops::{Deref, DerefMut};
Expand Down Expand Up @@ -156,6 +157,11 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Clone> Deref for ProgramAcco

impl<'a, T: AccountSerialize + AccountDeserialize + Clone> DerefMut for ProgramAccount<'a, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
if !self.inner.info.is_writable {
fanatid marked this conversation as resolved.
Show resolved Hide resolved
msg!("The given ProgramAccount is not mutable");
panic!();
}

&mut DerefMut::deref_mut(&mut self.inner).account
}
}
Expand Down