logging: Fix HookLogInit() and HookLogWrite() info usage

There's two instances of WriterBackend::WriterInfo for a given
writer. One in Manager::WriterInfo that's accessible via
stream.writers and a copy within WriterFrontend.

Commit 78999d147d switched to use the
address of the frontend's info instance for HookLogWrite() invocations,
breaking users using the address for identification purposes.
This commit is contained in:
Arne Welzel 2025-01-14 10:30:44 +01:00
parent 300b3788e2
commit 927a06b9ab
3 changed files with 32 additions and 8 deletions

View file

@ -49,6 +49,8 @@ void Plugin::HookLogInit(const std::string& writer, const std::string& instantia
fprintf(stderr, "%.6f %-15s %s %d/%d %s\n", zeek::run_state::network_time, "| HookLogInit", info.path, local,
remote, d.Description());
info_addr_init = &info;
}
bool Plugin::HookLogWrite(const std::string& writer, const std::string& filter,
@ -62,5 +64,17 @@ bool Plugin::HookLogWrite(const std::string& writer, const std::string& filter,
else if ( round == 3 )
vals[1]->present = false;
if ( ! info_addr_write )
info_addr_write = &info;
else if ( info_addr_write != &info )
fprintf(stderr, "FAIL: subsequent info addr %p differs from %p\n", &info, info_addr_write);
return true;
}
void Plugin::Done() {
if ( ! info_addr_init || ! info_addr_write || info_addr_init != info_addr_write ) {
fprintf(stderr, "FAIL: info_addr_init=%p info_addr_write=%p\n", info_addr_init, info_addr_write);
exit(1);
}
}

View file

@ -17,8 +17,13 @@ protected:
// Overridden from plugin::Plugin.
zeek::plugin::Configuration Configure() override;
// Overridden from plugin::Plugin.
void Done() override;
private:
int round;
const zeek::logging::WriterBackend::WriterInfo* info_addr_init = nullptr;
const zeek::logging::WriterBackend::WriterInfo* info_addr_write = nullptr;
};
extern Plugin plugin;