@@ -13,7 +13,7 @@ use crate::results::{
13
13
result_query_success_to_queryresult,
14
14
} ;
15
15
use crate :: {
16
- oom_handler,
16
+ oom_handler, recursion_depth ,
17
17
utils:: { validate_const_ptr, validate_mut_ptr} ,
18
18
} ;
19
19
@@ -116,6 +116,19 @@ pub unsafe extern "C" fn ecall_init(
116
116
sig_info : * const u8 ,
117
117
sig_info_len : usize ,
118
118
) -> InitResult {
119
+ let _recursion_guard = match recursion_depth:: guard ( ) {
120
+ Ok ( rg) => rg,
121
+ Err ( err) => {
122
+ // https://github.com/enigmampc/SecretNetwork/pull/517#discussion_r481924571
123
+ // I believe that this error condition is currently unreachable.
124
+ // I think we can safely remove it completely right now, and have
125
+ // recursion_depth::increment() simply increment the counter with no further checks,
126
+ // but i wanted to stay on the safe side here, in case something changes in the
127
+ // future, and we can easily spot that we forgot to add a limit somewhere.
128
+ error ! ( "recursion limit exceeded, can not perform init!" ) ;
129
+ return InitResult :: Failure { err } ;
130
+ }
131
+ } ;
119
132
if let Err ( err) = oom_handler:: register_oom_handler ( ) {
120
133
error ! ( "Could not register OOM handler!" ) ;
121
134
return InitResult :: Failure { err } ;
@@ -200,6 +213,19 @@ pub unsafe extern "C" fn ecall_handle(
200
213
sig_info : * const u8 ,
201
214
sig_info_len : usize ,
202
215
) -> HandleResult {
216
+ let _recursion_guard = match recursion_depth:: guard ( ) {
217
+ Ok ( rg) => rg,
218
+ Err ( err) => {
219
+ // https://github.com/enigmampc/SecretNetwork/pull/517#discussion_r481924571
220
+ // I believe that this error condition is currently unreachable.
221
+ // I think we can safely remove it completely right now, and have
222
+ // recursion_depth::increment() simply increment the counter with no further checks,
223
+ // but i wanted to stay on the safe side here, in case something changes in the
224
+ // future, and we can easily spot that we forgot to add a limit somewhere.
225
+ error ! ( "recursion limit exceeded, can not perform handle!" ) ;
226
+ return HandleResult :: Failure { err } ;
227
+ }
228
+ } ;
203
229
if let Err ( err) = oom_handler:: register_oom_handler ( ) {
204
230
error ! ( "Could not register OOM handler!" ) ;
205
231
return HandleResult :: Failure { err } ;
@@ -280,6 +306,19 @@ pub unsafe extern "C" fn ecall_query(
280
306
msg : * const u8 ,
281
307
msg_len : usize ,
282
308
) -> QueryResult {
309
+ let _recursion_guard = match recursion_depth:: guard ( ) {
310
+ Ok ( rg) => rg,
311
+ Err ( err) => {
312
+ // https://github.com/enigmampc/SecretNetwork/pull/517#discussion_r481924571
313
+ // I believe that this error condition is currently unreachable.
314
+ // I think we can safely remove it completely right now, and have
315
+ // recursion_depth::increment() simply increment the counter with no further checks,
316
+ // but i wanted to stay on the safe side here, in case something changes in the
317
+ // future, and we can easily spot that we forgot to add a limit somewhere.
318
+ error ! ( "recursion limit exceeded, can not perform query!" ) ;
319
+ return QueryResult :: Failure { err } ;
320
+ }
321
+ } ;
283
322
if let Err ( err) = oom_handler:: register_oom_handler ( ) {
284
323
error ! ( "Could not register OOM handler!" ) ;
285
324
return QueryResult :: Failure { err } ;
0 commit comments