MCPcopy Create free account
hub / github.com/cel-expr/cel-go / FuzzEval

Function FuzzEval

fuzzing/fuzz_eval.go:26–59  ·  view source on GitHub ↗

FuzzEval evaluates a CEL expression with variable inputs generated by libprotobuf-mutator.

(data []byte)

Source from the content-addressed store, hash-verified

24
25// FuzzEval evaluates a CEL expression with variable inputs generated by libprotobuf-mutator.
26func FuzzEval(data []byte) int {
27 gen := &FuzzVariables{}
28 err := proto.Unmarshal(data, gen)
29 if err != nil {
30 panic("Failed to unmarshal LPM generated variables")
31 }
32
33 declares := make([]*exprpb.Decl, 0, len(gen.Inputs))
34 for k := range gen.Inputs {
35 declares = append(declares, decls.NewVar(k, decls.String))
36 }
37 env, err := getCELFuzzEnv()
38 if err != nil {
39 panic("impossible to create env")
40 }
41
42 env, err = env.Extend(cel.Declarations(declares...))
43 if err != nil {
44 panic("impossible to create env")
45 }
46
47 ast, issues := env.Compile(gen.Expr)
48 if issues != nil && issues.Err() != nil {
49 return 0
50 }
51 prg, err := env.Program(ast)
52 if err != nil {
53 return 0
54 }
55
56 _, _, _ = prg.Eval(gen.Inputs)
57
58 return 1
59}
60

Callers 1

TestEvalLPMFunction · 0.85

Calls 8

NewVarFunction · 0.92
DeclarationsFunction · 0.92
getCELFuzzEnvFunction · 0.85
ErrMethod · 0.80
ProgramMethod · 0.80
CompileMethod · 0.65
EvalMethod · 0.65
ExtendMethod · 0.45

Tested by 1

TestEvalLPMFunction · 0.68