Skip to content
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
45 changes: 45 additions & 0 deletions test/fuzzing/fuzz_validate.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// fuzz_validate.c — libFuzzer harness for the clib manifest validator
// (src/common/clib-validate.c).
//
// Threat model (see coverage-pipeline-report.md in the OSS-Fuzz repo):
// * Untrusted input: clib.json / package.json manifest files. In
// production the validator runs on manifests fetched from third-party
// repositories before `clib install` / `clib update` act on them
// (src/clib-install.c, src/clib-update.c), i.e. exactly the supply
// chain input an attacker controls.
// * Trust boundary: clib_validate(file) — bytes-in via a file.
// * Expected bug classes: memory safety in the JSON parsing (parson) and
// repo-string parsing (parse-repo) under validation, and validation
// logic errors.
//
// Harness shape (classic bytes-into-parser): the input is written to a
// fixed file path and validated. The file is overwritten (not unlinked)
// every iteration.
//
// Note: clib-validate.c is not part of the current fuzz build at all (it is
// never referenced by the existing fuzz_manifest link); the OSS-Fuzz side
// build script of this pair compiles it in.

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "../../src/common/clib-validate.h"

#define FUZZ_MANIFEST_PATH "/tmp/clib-fuzz-validate.json"

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (size < 2)
return 0;

FILE *fp = fopen(FUZZ_MANIFEST_PATH, "wb");
if (!fp)
return 0;
fwrite(data, 1, size, fp);
fclose(fp);

(void)clib_validate(FUZZ_MANIFEST_PATH);
return 0;
}
45 changes: 45 additions & 0 deletions test/fuzzing/fuzz_validate.dict
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# fuzz_validate.dict — tokens for the clib manifest validator harness.
# Inputs are clib.json / package.json manifests (untrusted supply-chain data).

key_name="name"
key_version="version"
key_repo="repo"
key_description="description"
key_license="license"
key_keywords="keywords"
key_src="src"
key_install="install"
key_development="development"
key_dependencies="dependencies"
key_flags="flags"
key_cflags="cflags"
key_prefix="prefix"
key_makefile="makefile"
key_configure="configure"
kw_name="\"name\""
kw_repo="\"repo\""
kw_version="\"version\""
kw_license="\"license\""
kw_description="\"description\""
kw_keywords="\"keywords\""
kw_src="\"src\""
kw_install="\"install\""
repo_slug="clibs/clib"
repo_slug="jane/foo"
repo_url="https://github.com/clibs/clib"
repo_git="git@github.com:clibs/clib.git"
version="1.0.0"
version="master"
version="*"
license="MIT"
license="Apache-2.0"
c_file=".c"
h_file=".h"
src_file="src/foo.c"
true="true"
false="false"
null="null"
open_obj="{"
close_obj="}"
open_arr="["
close_arr="]"
9 changes: 9 additions & 0 deletions test/fuzzing/seeds/fuzz_validate/01-valid-full.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "foo",
"version": "1.0.0",
"repo": "clibs/foo",
"description": "a test package",
"license": "MIT",
"keywords": ["test", "fuzz"],
"src": ["foo.c", "foo.h"]
}
4 changes: 4 additions & 0 deletions test/fuzzing/seeds/fuzz_validate/02-minimal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "foo",
"version": "1.0.0"
}
6 changes: 6 additions & 0 deletions test/fuzzing/seeds/fuzz_validate/03-missing-src-install.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "foo",
"version": "1.0.0",
"description": "d",
"license": "MIT"
}
5 changes: 5 additions & 0 deletions test/fuzzing/seeds/fuzz_validate/04-src-non-array.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "foo",
"version": "1.0.0",
"src": "foo.c"
}
1 change: 1 addition & 0 deletions test/fuzzing/seeds/fuzz_validate/05-garbage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is not json at all {{{
1 change: 1 addition & 0 deletions test/fuzzing/seeds/fuzz_validate/06-array-root.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1, 2, 3]
6 changes: 6 additions & 0 deletions test/fuzzing/seeds/fuzz_validate/07-repo-variants.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "foo",
"version": "1.0.0",
"repo": "https://github.com/clibs/foo",
"install": "make install"
}
1 change: 1 addition & 0 deletions test/fuzzing/seeds/fuzz_validate/08-empty-object.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
5 changes: 5 additions & 0 deletions test/fuzzing/seeds/fuzz_validate/09-install-only.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "foo",
"version": "1.0.0",
"install": "make"
}