@@ -194,14 +194,14 @@ impl NeuronPrecompile {
194
194
fn parse_serve_axon_tls_parameters (
195
195
data : & [ u8 ] ,
196
196
) -> Result < ( u16 , u32 , u128 , u16 , u8 , u8 , u8 , u8 , vec:: Vec < u8 > ) , PrecompileFailure > {
197
- if data. len ( ) < 288 {
197
+ let data_len = data. len ( ) ;
198
+ if data_len < 288 {
198
199
return Err ( PrecompileFailure :: Error {
199
200
exit_status : ExitError :: InvalidRange ,
200
201
} ) ;
201
202
}
202
- let mut netuid_vec = [ 0u8 ; 2 ] ;
203
- netuid_vec. copy_from_slice ( get_slice ( data, 30 , 32 ) ?) ;
204
- let netuid = u16:: from_be_bytes ( netuid_vec) ;
203
+
204
+ let netuid = parse_netuid ( data, 30 ) ?;
205
205
206
206
let mut version_vec = [ 0u8 ; 4 ] ;
207
207
version_vec. copy_from_slice ( get_slice ( data, 60 , 64 ) ?) ;
@@ -224,6 +224,17 @@ impl NeuronPrecompile {
224
224
len_position_vec. copy_from_slice ( get_slice ( data, 286 , 288 ) ?) ;
225
225
let len_position = u16:: from_be_bytes ( len_position_vec) as usize ;
226
226
227
+ if len_position > data_len {
228
+ log:: error!(
229
+ "the start position of certificate as {} is bigger than whole data len {}" ,
230
+ subnet_contact_start,
231
+ data_len
232
+ ) ;
233
+ return Err ( PrecompileFailure :: Error {
234
+ exit_status : ExitError :: InvalidRange ,
235
+ } ) ;
236
+ }
237
+
227
238
let mut len_vec = [ 0u8 ; 2 ] ;
228
239
len_vec. copy_from_slice ( get_slice ( data, len_position + 30 , len_position + 32 ) ?) ;
229
240
let vec_len = u16:: from_be_bytes ( len_vec) as usize ;
0 commit comments