HdrHistogram_c icon indicating copy to clipboard operation
HdrHistogram_c copied to clipboard

Suggest fuzzer for hdr_log_read()

Open autofuzzoss opened this issue 3 years ago • 0 comments

I suggest this fuzzer for continuous vulnerability checks.


/*
 * This fuzzer is generated by UTopia with some manual modifications.
 * (UTopia Project: https://github.com/Samsung/UTopia)
 */

#include "FuzzedDataProvider.h"
#include <fstream>
#include <hdr/hdr_histogram_log.h>
#include <math.h>

bool save_file(std::string Path, std::string Content) {
  std::ofstream OFS(Path);
  if (!OFS.is_open())
    return false;

  OFS << Content;
  return true;
}

void fuzz_hdr_log_read(FuzzedDataProvider &provider) {
  auto input = provider.ConsumeRemainingBytesAsString();
  const char *file_name = "input.log";
  save_file(file_name, input);

  struct hdr_histogram *h = NULL;
  hdr_timespec timestamp, interval;

  FILE *f = fopen(file_name, "r");
  if (NULL == f) {
    fprintf(stderr, "Open file: [%d] %s", errno, strerror(errno));
    return;
  }

  hdr_log_read(NULL, f, &h, &timestamp, &interval);
  fclose(f);
  remove(file_name);
}

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, uint32_t size) {
  FuzzedDataProvider provider(data, size);
  fuzz_hdr_log_read(provider);
  
  return 0;
}

autofuzzoss avatar Oct 11 '22 06:10 autofuzzoss