#include "cf.h" #include "p.h" #include #include #include #include #include #include #ifndef TOBI_SRC_DIR #define TOBI_SRC_DIR "." #endif static int run_one(const uint8_t *data, size_t len) { tobi_parse_result r; (void)tobi_parse(data, len, 0, &r); if (r.root) { (void)tobi_cf_recover(r.root, &r.diag); } tobi_parse_result_free(&r); return 0; } static void file_one(const char *path) { FILE *fp = fopen(path, "rb"); if (!fp) { return; } (void)fseek(fp, 0, SEEK_END); long n = ftell(fp); rewind(fp); if (n < 0) { fclose(fp); return; } uint8_t *buf = malloc((size_t)n ? (size_t)n : 1); if (!buf) { fclose(fp); abort(); } if ((size_t)n == fread(buf, 1, (size_t)n, fp)) { (void)run_one(buf, (size_t)n); for (size_t i = 0; i <= (size_t)n; i++) { (void)run_one(buf, i); } } free(buf); fclose(fp); } static void seed_dir(const char *path) { DIR *dir = opendir(path); if (!dir) { return; } struct dirent *de = NULL; while ((de = readdir(dir)) != NULL) { if (de->d_name[0] == '.') { continue; } char file[1024]; snprintf(file, sizeof(file), "%s/%s", path, de->d_name); struct stat st; if (stat(file, &st) == 0 && S_ISREG(st.st_mode)) { file_one(file); } } closedir(dir); } int main(void) { seed_dir(TOBI_SRC_DIR "/fuzz/seed"); uint32_t x = 0x12345678u; for (size_t n = 0; n < 512; n++) { uint8_t buf[256]; for (size_t i = 0; i < sizeof(buf); i++) { x = x * 1664525u + 1013904223u; buf[i] = (uint8_t)(x >> 24); } (void)run_one(buf, n % sizeof(buf)); } return 0; }