mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 07:38:19 +00:00
Adding missing check that a plugin's API version matches what Bro defines.
This commit is contained in:
parent
024c26d982
commit
382b946098
5 changed files with 27 additions and 9 deletions
|
@ -219,6 +219,10 @@ bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_
|
||||||
current_plugin->SetDynamic(true);
|
current_plugin->SetDynamic(true);
|
||||||
current_plugin->DoConfigure();
|
current_plugin->DoConfigure();
|
||||||
|
|
||||||
|
if ( current_plugin->APIVersion() != BRO_PLUGIN_API_VERSION )
|
||||||
|
reporter->FatalError("plugin's API version does not match Bro (expected %d, got %d in %s)",
|
||||||
|
BRO_PLUGIN_API_VERSION, current_plugin->APIVersion(), path);
|
||||||
|
|
||||||
// We execute the pre-script initialization here; this in
|
// We execute the pre-script initialization here; this in
|
||||||
// fact could be *during* script initialization if we got
|
// fact could be *during* script initialization if we got
|
||||||
// triggered via @load-plugin.
|
// triggered via @load-plugin.
|
||||||
|
|
|
@ -33,13 +33,6 @@ const char* plugin::hook_name(HookType h)
|
||||||
return hook_names[int(h)];
|
return hook_names[int(h)];
|
||||||
}
|
}
|
||||||
|
|
||||||
Configuration::Configuration()
|
|
||||||
{
|
|
||||||
name = "";
|
|
||||||
description = "";
|
|
||||||
api_version = BRO_PLUGIN_API_VERSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
BifItem::BifItem(const std::string& arg_id, Type arg_type)
|
BifItem::BifItem(const std::string& arg_id, Type arg_type)
|
||||||
{
|
{
|
||||||
id = arg_id;
|
id = arg_id;
|
||||||
|
|
|
@ -10,7 +10,10 @@
|
||||||
#include "analyzer/Component.h"
|
#include "analyzer/Component.h"
|
||||||
#include "file_analysis/Component.h"
|
#include "file_analysis/Component.h"
|
||||||
|
|
||||||
static const int BRO_PLUGIN_API_VERSION = 2;
|
// We allow to override this externally for testing purposes.
|
||||||
|
#ifndef BRO_PLUGIN_API_VERSION
|
||||||
|
#define BRO_PLUGIN_API_VERSION 2
|
||||||
|
#endif
|
||||||
|
|
||||||
class ODesc;
|
class ODesc;
|
||||||
class Func;
|
class Func;
|
||||||
|
@ -75,13 +78,23 @@ public:
|
||||||
std::string description; //< A short textual description of the plugin. Mandatory.
|
std::string description; //< A short textual description of the plugin. Mandatory.
|
||||||
VersionNumber version; //< THe plugin's version. Optional.
|
VersionNumber version; //< THe plugin's version. Optional.
|
||||||
|
|
||||||
Configuration();
|
// We force this to inline so that the API version gets hardcoded
|
||||||
|
// into the external plugin. (Technically, it's not a "force", just a
|
||||||
|
// strong hint.). The attribute seems generally available.
|
||||||
|
inline Configuration() __attribute__((always_inline));
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class Plugin;
|
friend class Plugin;
|
||||||
int api_version; // Current BRO_PLUGIN_API_VERSION. Automatically set.
|
int api_version; // Current BRO_PLUGIN_API_VERSION. Automatically set.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline Configuration::Configuration()
|
||||||
|
{
|
||||||
|
name = "";
|
||||||
|
description = "";
|
||||||
|
api_version = BRO_PLUGIN_API_VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class describing an item defined in \c *.bif file.
|
* A class describing an item defined in \c *.bif file.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
fatal error in /home/robin/bro/master/scripts/base/init-bare.bro, line 1: plugin's API version does not match Bro (expected 2, got 42 in /home/robin/bro/master/testing/btest/.tmp/plugins.api-version-mismatch//lib/Demo-Foo.linux-x86_64.so)
|
7
testing/btest/plugins/api-version-mismatch.sh
Normal file
7
testing/btest/plugins/api-version-mismatch.sh
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin Demo Foo
|
||||||
|
# @TEST-EXEC: bash %INPUT
|
||||||
|
# @TEST-EXEC: make BRO=${DIST}
|
||||||
|
# @TEST-EXEC-FAIL: BRO_PLUGIN_PATH=`pwd` bro -NN Demo::Foo >>output 2>&1
|
||||||
|
# @TEST-EXEC: btest-diff output
|
||||||
|
|
||||||
|
( echo '#define BRO_PLUGIN_API_VERSION 42'; cat src/Plugin.cc; ) >src/Plugin.cc.tmp && mv src/Plugin.cc.tmp src/Plugin.cc
|
Loading…
Add table
Add a link
Reference in a new issue