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

Function generateFuzzedNodeXML

fuzzing/bt_fuzzer.cpp:23–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21 "threshold", "max_repeats" };
22
23std::string generateFuzzedNodeXML(FuzzedDataProvider& fdp, int depth = 0)
24{
25 // Prevent stack overflow with max depth
26 if(depth > 6)
27 { // Reasonable limit for XML tree depth
28 return "<AlwaysSuccess/>";
29 }
30
31 std::string xml;
32 const std::string node_type = fdp.PickValueInArray(NODE_TYPES);
33
34 xml += "<" + node_type;
35
36 size_t num_attributes = fdp.ConsumeIntegralInRange<size_t>(0, 3);
37 for(size_t i = 0; i < num_attributes; i++)
38 {
39 const std::string attr = fdp.PickValueInArray(NODE_ATTRIBUTES);
40 std::string value = fdp.ConsumeRandomLengthString(10);
41 xml += " " + attr + "=\"" + value + "\"";
42 }
43
44 if(depth > 3 || fdp.ConsumeBool())
45 {
46 xml += "/>";
47 }
48 else
49 {
50 xml += ">";
51 // Add some child nodes recursively with depth limit
52 size_t num_children = fdp.ConsumeIntegralInRange<size_t>(0, 2);
53 for(size_t i = 0; i < num_children; i++)
54 {
55 xml += generateFuzzedNodeXML(fdp, depth + 1);
56 }
57 xml += "</" + node_type + ">";
58 }
59
60 return xml;
61}
62
63extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
64{

Callers 1

LLVMFuzzerTestOneInputFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected