Skip to content

Suggest fuzzer for libconfig. #224

Description

@autofuzzoss

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 "libconfig.h"
#include <FuzzedDataProvider.h>
#include <fstream>

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

  OFS << Content;
  return true;
}

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, uint32_t size) {
  config_t cfg;
  int ok;
  const char *str;
  FuzzedDataProvider provider(data, size);
  auto Input1 = provider.ConsumeRandomLengthString(10);
  auto Input2 = provider.ConsumeRandomLengthString(10);
  auto Input3 = provider.ConsumeRemainingBytesAsString();
  if (!saveFile("input", Input3))
    return 0;

  config_init(&cfg);
  config_set_include_dir(&cfg, Input1.c_str());

  ok = config_read_file(&cfg, "input");
  if (!ok) {
    config_error_text(&cfg);
    config_error_line(&cfg);
  }

  config_lookup_string(&cfg, Input2.c_str(), &str);
  config_destroy(&cfg);
  return 0;
}

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions