Add OSS-Fuzz Zeek script search path to fuzzers

This commit is contained in:
Jon Siwek 2020-04-24 17:53:01 -07:00
parent a4244bc72b
commit 98845e89aa
4 changed files with 57 additions and 32 deletions

View file

@ -1745,6 +1745,38 @@ static string find_file_in_path(const string& filename, const string& path,
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,
const string& opt_ext)
{