소스 검색

zkas: fix panic occurring in nested function calls

This issue was discovered by fuzzing.

Change the `unimplemented()!` panic macro to error handling that informs
the user that using Literals and Functions in nested function calls is
not yet supported. This should be a slightly more friendly developer
experience. Changing this from a panic to an error allows us to continue
with further fuzzing.
y 2 년 전
부모
커밋
0a61ec37fb
1개의 변경된 파일15개의 추가작업 그리고 1개의 파일을 삭제
  1. 15 1
      src/zkas/analyzer.rs

+ 15 - 1
src/zkas/analyzer.rs

@@ -186,6 +186,8 @@ impl Analyzer {
 
                     let mut rhs_inner = vec![];
                     for (inner_idx, i) in func.rhs.iter().enumerate() {
+                        // TODO: Implement cases where `i` is type Arg::Literal
+                        // TODO: Implement cases where `i` is type Arg::Func
                         if let Arg::Var(v) = i {
                             if let Some(var_ref) = self.lookup_var(&v.name) {
                                 let (var_type, ln, col) = match var_ref {
@@ -218,8 +220,20 @@ impl Analyzer {
                                 v.line,
                                 v.column,
                             ))
+                        } else if let Arg::Lit(l) = i {
+                            return Err(self.error.abort(
+                                &format!("Expected argument `{}` to be of type Variable. Literals are not yet supported in nested function calls.", l.name),
+                                l.line,
+                                l.column,
+                            ))
+                        } else if let Arg::Func(f) = i {
+                            return Err(self.error.abort(
+                                &format!("Expected argument `{}` to be of type Variable. Nested function calls are not yet supported beyond a depth of 1.", Opcode::name(&f.opcode)),
+                                f.line,
+                                0,
+                            ))
                         } else {
-                            unimplemented!()
+                            unreachable!();
                         }
                     }