Skip to content

add four new fuzzing harnesses#4076

Open
DavidKorczynski wants to merge 1 commit intoClusterLabs:mainfrom
DavidKorczynski:new-fuzzers
Open

add four new fuzzing harnesses#4076
DavidKorczynski wants to merge 1 commit intoClusterLabs:mainfrom
DavidKorczynski:new-fuzzers

Conversation

@DavidKorczynski
Copy link
Copy Markdown
Contributor

The main goal here is to increase code coverage of the OSS-Fuzz project. A recent code coverage report is available here:
https://storage.googleapis.com/oss-fuzz-coverage/pacemaker/reports/20260331/linux/src/report.html

The main goal here is to increase code coverage of the OSS-Fuzz project.
A recent code coverage report is available here:
https://storage.googleapis.com/oss-fuzz-coverage/pacemaker/reports/20260331/linux/src/report.html

Signed-off-by: David Korczynski <david@adalogics.com>
@knet-jenkins
Copy link
Copy Markdown

knet-jenkins bot commented Mar 31, 2026

Can one of the project admins check and authorise this run please: https://haci.fast.eng.rdu2.dc.redhat.com/job/pacemaker/job/pacemaker-pipeline/job/PR-4076/1/input

Copy link
Copy Markdown
Contributor

@nrwahl2 nrwahl2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

xmlNode *xml = NULL;
xmlNode *result = NULL;

if (size < 20) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get comments explaining the magic size numbers, here and in the other harnesses?

// Run the ACL filtered copy with a non-root user
// pcmk_acl_required() returns false for "root" and "hacluster", so we use
// a regular user name to ensure ACL processing is actually exercised.
xml_acl_filtered_copy("fuzzuser", xml, xml, &result);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth fuzzing with different usernames (returning -1 for "root" or "hacluster" to exclude those from the corpus)? I'm new to libfuzzer and unsure of best practices for coverage.

Speaking of which... I don't know whether or how the corpus gets seeded with valid inputs. If we're relying on purely random data here, I would expect it to take an unreasonably long time to get anything remotely meaningful, even if we get valid XML. If all we care about is testing garbage input, that's fine.

// a regular user name to ensure ACL processing is actually exercised.
xml_acl_filtered_copy("fuzzuser", xml, xml, &result);

if (result != NULL) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be guarded. pcmk__xml_free() is NULL-safe.

* This provides enough structure for XPath operations to have meaningful
* targets (nodes, resources, constraints, status).
*/
static const char *BASE_CIB =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually reserve all-caps for #define'd constants. I'd prefer to see this as either a #define or base_cib

* targets (nodes, resources, constraints, status).
*/
static const char *BASE_CIB =
"<cib admin_epoch=\"1\" epoch=\"1\" num_updates=\"0\">"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure you can use single quotes within the XML and avoid all the backslash-escaping

@@ -0,0 +1,55 @@
/*
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should either change the name of this file or change our documentation.

That directory has a file for each fuzzed source file, named the same except ending in _fuzzer.c (for example, lib/common/fuzzers/strings_fuzzer.c has fuzzing for lib/common/strings.c).

There is no xml_parse.c file.

xml = pcmk__xml_parse(input);

// If parsing succeeded, exercise some read-only operations on the result
if (xml != NULL) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might as well be consistent with the other three files in this commit, and return early if xml == NULL, de-nesting the body of this if statement.

pcmk__xe_id(xml);

// Iterate children — exercises XML tree traversal
for (xmlNode *child = pcmk__xe_first_child(xml, NULL, NULL, NULL);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can use const xmlNode *child


// If parsing succeeded, exercise some read-only operations on the result
if (xml != NULL) {
// Access the element name and ID (common post-parse operations)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are we accessing the element name?

// Parse the fuzz input as XML
xml = pcmk__xml_parse(input);
if (xml == NULL) {
free(input);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want, you can do all the freeing after a done: label and just goto done here. We frequently do cleanup using goto done, even though we don't use goto for much of anything else. It helps us not to forget to free anything in early returns.

It doesn't matter to me. Note that this applies to other files in this commit too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants