1
1
//! Program state processor
2
2
3
3
use {
4
- crate :: {
5
- error:: RecordError ,
6
- instruction:: RecordInstruction ,
7
- state:: { Data , RecordData } ,
8
- } ,
4
+ crate :: { error:: RecordError , instruction:: RecordInstruction , state:: RecordData } ,
9
5
solana_program:: {
10
6
account_info:: { next_account_info, AccountInfo } ,
11
7
entrypoint:: ProgramResult ,
@@ -46,7 +42,13 @@ pub fn process_instruction(
46
42
let authority_info = next_account_info ( account_info_iter) ?;
47
43
48
44
let raw_data = & mut data_info. data . borrow_mut ( ) ;
49
- let account_data = pod_from_bytes_mut :: < RecordData > ( raw_data) ?;
45
+ if raw_data. len ( ) < RecordData :: WRITABLE_START_INDEX {
46
+ return Err ( ProgramError :: InvalidAccountData ) ;
47
+ }
48
+
49
+ let account_data = pod_from_bytes_mut :: < RecordData > (
50
+ & mut raw_data[ ..RecordData :: WRITABLE_START_INDEX ] ,
51
+ ) ?;
50
52
if account_data. is_initialized ( ) {
51
53
msg ! ( "Record account already initialized" ) ;
52
54
return Err ( ProgramError :: AccountAlreadyInitialized ) ;
@@ -63,7 +65,11 @@ pub fn process_instruction(
63
65
let authority_info = next_account_info ( account_info_iter) ?;
64
66
{
65
67
let raw_data = & data_info. data . borrow ( ) ;
66
- let account_data = pod_from_bytes :: < RecordData > ( raw_data) ?;
68
+ if raw_data. len ( ) < RecordData :: WRITABLE_START_INDEX {
69
+ return Err ( ProgramError :: InvalidAccountData ) ;
70
+ }
71
+ let account_data =
72
+ pod_from_bytes :: < RecordData > ( & raw_data[ ..RecordData :: WRITABLE_START_INDEX ] ) ?;
67
73
if !account_data. is_initialized ( ) {
68
74
msg ! ( "Record account not initialized" ) ;
69
75
return Err ( ProgramError :: UninitializedAccount ) ;
@@ -86,7 +92,12 @@ pub fn process_instruction(
86
92
let authority_info = next_account_info ( account_info_iter) ?;
87
93
let new_authority_info = next_account_info ( account_info_iter) ?;
88
94
let raw_data = & mut data_info. data . borrow_mut ( ) ;
89
- let account_data = pod_from_bytes_mut :: < RecordData > ( raw_data) ?;
95
+ if raw_data. len ( ) < RecordData :: WRITABLE_START_INDEX {
96
+ return Err ( ProgramError :: InvalidAccountData ) ;
97
+ }
98
+ let account_data = pod_from_bytes_mut :: < RecordData > (
99
+ & mut raw_data[ ..RecordData :: WRITABLE_START_INDEX ] ,
100
+ ) ?;
90
101
if !account_data. is_initialized ( ) {
91
102
msg ! ( "Record account not initialized" ) ;
92
103
return Err ( ProgramError :: UninitializedAccount ) ;
@@ -102,7 +113,12 @@ pub fn process_instruction(
102
113
let authority_info = next_account_info ( account_info_iter) ?;
103
114
let destination_info = next_account_info ( account_info_iter) ?;
104
115
let raw_data = & mut data_info. data . borrow_mut ( ) ;
105
- let account_data = pod_from_bytes_mut :: < RecordData > ( raw_data) ?;
116
+ if raw_data. len ( ) < RecordData :: WRITABLE_START_INDEX {
117
+ return Err ( ProgramError :: InvalidAccountData ) ;
118
+ }
119
+ let account_data = pod_from_bytes_mut :: < RecordData > (
120
+ & mut raw_data[ ..RecordData :: WRITABLE_START_INDEX ] ,
121
+ ) ?;
106
122
if !account_data. is_initialized ( ) {
107
123
msg ! ( "Record not initialized" ) ;
108
124
return Err ( ProgramError :: UninitializedAccount ) ;
@@ -114,7 +130,6 @@ pub fn process_instruction(
114
130
* * destination_info. lamports . borrow_mut ( ) = destination_starting_lamports
115
131
. checked_add ( data_lamports)
116
132
. ok_or ( RecordError :: Overflow ) ?;
117
- account_data. data = Data :: default ( ) ;
118
133
Ok ( ( ) )
119
134
}
120
135
}
0 commit comments