mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 15:48:19 +00:00
Add OSS-Fuzz Zeek script search path to fuzzers
This commit is contained in:
parent
a4244bc72b
commit
98845e89aa
4 changed files with 57 additions and 32 deletions
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
#include "zeek-setup.h"
|
#include "zeek-setup.h"
|
||||||
|
@ -11,6 +12,22 @@
|
||||||
|
|
||||||
extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv)
|
extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv)
|
||||||
{
|
{
|
||||||
|
auto zeekpath = getenv("ZEEKPATH");
|
||||||
|
|
||||||
|
if ( ! zeekpath )
|
||||||
|
{
|
||||||
|
// Set up an expected script search path for use with OSS-Fuzz
|
||||||
|
auto constexpr oss_fuzz_scripts = "oss-fuzz-zeek-scripts";
|
||||||
|
auto fuzzer_path = get_exe_path(*argv[0]);
|
||||||
|
auto fuzzer_dir = SafeDirname(fuzzer_path).result;
|
||||||
|
std::string fs = fmt("%s/%s", fuzzer_dir.data(), oss_fuzz_scripts);
|
||||||
|
auto p = fs.data();
|
||||||
|
auto oss_fuzz_zeekpath = fmt(".:%s:%s/policy:%s/site", p, p, p);
|
||||||
|
|
||||||
|
if ( setenv("ZEEKPATH", oss_fuzz_zeekpath, true) == -1 )
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
zeek::Options options;
|
zeek::Options options;
|
||||||
options.scripts_to_load.emplace_back("local.zeek");
|
options.scripts_to_load.emplace_back("local.zeek");
|
||||||
options.script_options_to_set.emplace_back("Site::local_nets={10.0.0.0/8}");
|
options.script_options_to_set.emplace_back("Site::local_nets={10.0.0.0/8}");
|
||||||
|
|
32
src/util.cc
32
src/util.cc
|
@ -1745,6 +1745,38 @@ static string find_file_in_path(const string& filename, const string& path,
|
||||||
return string();
|
return string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string get_exe_path(const std::string& invocation)
|
||||||
|
{
|
||||||
|
if ( invocation.empty() )
|
||||||
|
return "";
|
||||||
|
|
||||||
|
if ( invocation[0] == '/' || invocation[0] == '~' )
|
||||||
|
// Absolute path
|
||||||
|
return invocation;
|
||||||
|
|
||||||
|
if ( invocation.find('/') != std::string::npos )
|
||||||
|
{
|
||||||
|
// Relative path
|
||||||
|
char cwd[PATH_MAX];
|
||||||
|
|
||||||
|
if ( ! getcwd(cwd, sizeof(cwd)) )
|
||||||
|
{
|
||||||
|
fprintf(stderr, "failed to get current directory: %s\n",
|
||||||
|
strerror(errno));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::string(cwd) + "/" + invocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto path = getenv("PATH");
|
||||||
|
|
||||||
|
if ( ! path )
|
||||||
|
return "";
|
||||||
|
|
||||||
|
return find_file(invocation, path);
|
||||||
|
}
|
||||||
|
|
||||||
string find_file(const string& filename, const string& path_set,
|
string find_file(const string& filename, const string& path_set,
|
||||||
const string& opt_ext)
|
const string& opt_ext)
|
||||||
{
|
{
|
||||||
|
|
|
@ -346,6 +346,14 @@ std::string normalize_path(std::string_view path);
|
||||||
*/
|
*/
|
||||||
std::string without_bropath_component(std::string_view path);
|
std::string without_bropath_component(std::string_view path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the full path used to invoke some executable.
|
||||||
|
* @param invocation any possible string that may be seen in argv[0], such as
|
||||||
|
* absolute path, relative path, or name to lookup in PATH.
|
||||||
|
* @return the absolute path to the executable file
|
||||||
|
*/
|
||||||
|
std::string get_exe_path(const std::string& invocation);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Locate a file within a given search path.
|
* Locate a file within a given search path.
|
||||||
* @param filename Name of a file to find.
|
* @param filename Name of a file to find.
|
||||||
|
|
|
@ -374,38 +374,6 @@ static std::vector<std::string> get_script_signature_files()
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string get_exe_path(const std::string& invocation)
|
|
||||||
{
|
|
||||||
if ( invocation.empty() )
|
|
||||||
return "";
|
|
||||||
|
|
||||||
if ( invocation[0] == '/' || invocation[0] == '~' )
|
|
||||||
// Absolute path
|
|
||||||
return invocation;
|
|
||||||
|
|
||||||
if ( invocation.find('/') != std::string::npos )
|
|
||||||
{
|
|
||||||
// Relative path
|
|
||||||
char cwd[PATH_MAX];
|
|
||||||
|
|
||||||
if ( ! getcwd(cwd, sizeof(cwd)) )
|
|
||||||
{
|
|
||||||
fprintf(stderr, "failed to get current directory: %s\n",
|
|
||||||
strerror(errno));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::string(cwd) + "/" + invocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto path = getenv("PATH");
|
|
||||||
|
|
||||||
if ( ! path )
|
|
||||||
return "";
|
|
||||||
|
|
||||||
return find_file(invocation, path);
|
|
||||||
}
|
|
||||||
|
|
||||||
zeek::SetupResult zeek::setup(int argc, char** argv, zeek::Options* zopts)
|
zeek::SetupResult zeek::setup(int argc, char** argv, zeek::Options* zopts)
|
||||||
{
|
{
|
||||||
ZEEK_LSAN_DISABLE();
|
ZEEK_LSAN_DISABLE();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue