MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / LLVMFuzzerTestOneInput

Function LLVMFuzzerTestOneInput

fuzzing/script_fuzzer.cpp:12–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10#include <fuzzer/FuzzedDataProvider.h>
11
12extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
13{
14 if(size < 4)
15 {
16 return 0;
17 }
18
19 FuzzedDataProvider fuzz_data(data, size);
20
21 try
22 {
23 BT::Ast::Environment env;
24 env.vars = BT::Blackboard::create();
25 env.enums = std::make_shared<BT::EnumsTable>();
26
27 // Add some test variables to the blackboard
28 env.vars->set("test_int", 42);
29 env.vars->set("test_double", 3.14);
30 env.vars->set("test_bool", true);
31 env.vars->set("test_string", std::string("test"));
32
33 // Add some test enums
34 (*env.enums)["RUNNING"] = 0;
35 (*env.enums)["SUCCESS"] = 1;
36 (*env.enums)["FAILURE"] = 2;
37
38 std::string script = fuzz_data.ConsumeRandomLengthString();
39
40 auto validation_result = BT::ValidateScript(script);
41
42 if(!validation_result)
43 {
44 auto parsed_script = BT::ParseScript(script);
45 if(parsed_script)
46 {
47 try
48 {
49 auto result = parsed_script.value()(env);
50
51 if(result.isNumber())
52 {
53 volatile auto num = result.cast<double>();
54 }
55
56 env.vars->set("result", result);
57
58 BT::Any read_back;
59 (void)env.vars->get("result", read_back);
60 }
61 catch(const BT::RuntimeError&) // NOLINT(bugprone-empty-catch)
62 {
63 // Intentionally empty - fuzzer expects exceptions
64 }
65 }
66 }
67
68 BT::ParseScriptAndExecute(env, script);
69 }

Callers

nothing calls this directly

Calls 9

createFunction · 0.85
stringFunction · 0.85
ValidateScriptFunction · 0.85
ParseScriptFunction · 0.85
ParseScriptAndExecuteFunction · 0.85
setMethod · 0.80
isNumberMethod · 0.80
valueMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected