Re-instantiate providing location information to LoadFile hooks.

#1835 subtly changed the semantics of the `LoadFile` plugin hook to no
longer have the current script location available for signature files
being loaded through `@load-sigs`. This was undocumented behavior, so
it's technically not a regression, but since at least one external
plugin is depending on it, this change restores the old behavior.
This commit is contained in:
Robin Sommer 2022-04-14 09:54:45 +02:00
parent d29160e9de
commit fccb9ccab0
No known key found for this signature in database
GPG key ID: 6BEDA4DA6B8B23E3
8 changed files with 66 additions and 11 deletions

View file

@ -266,6 +266,13 @@ bool RuleMatcher::ReadFiles(const std::vector<SignatureFile>& files)
if ( ! f.full_path )
f.full_path = util::find_file(f.file, util::zeek_path(), ".sig");
// We mimic previous Zeek versions by temporarily setting the current
// script location to the place where the loading happened. This
// behavior was never documented, but seems worth not breaking as some
// plugins ended up relying on it.
Location orig_location = detail::GetCurrentLocation();
detail::SetCurrentLocation(f.load_location);
std::pair<int, std::optional<std::string>> rc = {-1, std::nullopt};
rc.first = PLUGIN_HOOK_WITH_RESULT(
HOOK_LOAD_FILE, HookLoadFile(zeek::plugin::Plugin::SIGNATURES, f.file, *f.full_path),
@ -277,6 +284,9 @@ bool RuleMatcher::ReadFiles(const std::vector<SignatureFile>& files)
HookLoadFileExtended(zeek::plugin::Plugin::SIGNATURES, f.file, *f.full_path),
std::make_pair(-1, std::nullopt));
// Restore original location information.
detail::SetCurrentLocation(orig_location);
switch ( rc.first )
{
case -1: