Skip to content

tinyxml2 fuzzer update #13445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions projects/tinyxml2/fuzzer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <string>
#include <vector>
#include "tinyxml2/tinyxml2.h"

using namespace tinyxml2;

void fuzz_parse_xml(const uint8_t* data, size_t size) {
std::string xml(reinterpret_cast<const char*>(data), size);
XMLDocument doc;
doc.Parse(xml.c_str(), size);

XMLElement* root = doc.RootElement();
if (root) {
root->Name();
root->GetText();
root->GetDocument();

for (const XMLAttribute* attr = root->FirstAttribute(); attr; attr = attr->Next()) {
attr->Name();
attr->Value();
}

for (XMLElement* child = root->FirstChildElement(); child; child = child->NextSiblingElement()) {
child->Name();
}
}

doc.Print();
doc.Clear();
}

void fuzz_create_dom(const uint8_t* data, size_t size) {
std::string text(reinterpret_cast<const char*>(data), size);

XMLDocument doc;
XMLElement* root = doc.NewElement("root");
doc.InsertFirstChild(root);

XMLElement* child = doc.NewElement("child");
child->SetAttribute("id", 123); // May invoke unsafe behavior
child->SetText(text.c_str()); // Direct pass without checking
root->InsertEndChild(child);

doc.SaveFile("/dev/null");
doc.Clear();
}

void fuzz_api_surface(const uint8_t* data, size_t size) {
XMLDocument doc;
XMLNode* decl = doc.NewDeclaration();
doc.InsertFirstChild(decl);

XMLUnknown* unknown = doc.NewUnknown("<!-- fuzz -->");
doc.InsertEndChild(unknown);

XMLText* textNode = doc.NewText("FuzzTest");
doc.InsertEndChild(textNode);

doc.ErrorID();
doc.ErrorStr();
}

void fuzz_error_classification() {
for (int i = 0; i < 100; ++i) {
const char* name = XMLDocument::ErrorIDToName(static_cast<XMLError>(i));
std::string s(name); // no null check
}
}

extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
fuzz_parse_xml(data, size);
fuzz_create_dom(data, size);
fuzz_api_surface(data, size);
fuzz_error_classification();
return 0;
}
File renamed without changes.
28 changes: 0 additions & 28 deletions projects/tinyxml2/xmltest.cpp

This file was deleted.

38 changes: 0 additions & 38 deletions projects/tinyxml2/xmltest2.cpp

This file was deleted.

2 changes: 0 additions & 2 deletions projects/tinyxml2/xmltest2.options

This file was deleted.

Loading