Fix clang-tidy cppcoreguidelines-macro-usage warnings in headers

This commit is contained in:
Tim Wojtulewicz 2025-06-10 13:50:28 -07:00
parent 74bf987b82
commit e84c99fb14
31 changed files with 220 additions and 117 deletions

View file

@ -2,10 +2,10 @@
#pragma once #pragma once
#define ZEEK_SCRIPT_INSTALL_PATH "@ZEEK_SCRIPT_INSTALL_PATH@" constexpr char ZEEK_SCRIPT_INSTALL_PATH[] = "@ZEEK_SCRIPT_INSTALL_PATH@";
#define BRO_PLUGIN_INSTALL_PATH "@ZEEK_PLUGIN_DIR@" constexpr char BRO_PLUGIN_INSTALL_PATH[] = "@ZEEK_PLUGIN_DIR@";
#define ZEEK_PLUGIN_INSTALL_PATH "@ZEEK_PLUGIN_DIR@" constexpr char ZEEK_PLUGIN_INSTALL_PATH[] = "@ZEEK_PLUGIN_DIR@";
#define DEFAULT_ZEEKPATH "@DEFAULT_ZEEKPATH@" constexpr char DEFAULT_ZEEKPATH[] = "@DEFAULT_ZEEKPATH@";
#define ZEEK_SPICY_MODULE_PATH "@ZEEK_SPICY_MODULE_PATH@" constexpr char ZEEK_SPICY_MODULE_PATH[] = "@ZEEK_SPICY_MODULE_PATH@";
#define ZEEK_SPICY_LIBRARY_PATH "@ZEEK_SPICY_LIBRARY_PATH@" constexpr char ZEEK_SPICY_LIBRARY_PATH[] = "@ZEEK_SPICY_LIBRARY_PATH@";
#define ZEEK_SPICY_DATA_PATH "@ZEEK_SPICY_DATA_PATH@" constexpr char ZEEK_SPICY_DATA_PATH[] = "@ZEEK_SPICY_DATA_PATH@";

View file

@ -1,5 +1,6 @@
// See the file "COPYING" in the main distribution directory for copyright. // See the file "COPYING" in the main distribution directory for copyright.
// NOLINTBEGIN(modernize-macro-to-enum) // NOLINTBEGIN(modernize-macro-to-enum)
// NOLINTBEGIN(cppcoreguidelines-macro-usage)
#pragma once #pragma once
@ -308,4 +309,5 @@
/* compiled with Spicy support */ /* compiled with Spicy support */
#cmakedefine HAVE_SPICY #cmakedefine HAVE_SPICY
// NOLINTEND(cppcoreguidelines-macro-usage)
// NOLINTEND(modernize-macro-to-enum) // NOLINTEND(modernize-macro-to-enum)

View file

@ -1414,6 +1414,8 @@ TableValPtr DNS_Mgr::empty_addr_set() {
return make_intrusive<TableVal>(std::move(s)); return make_intrusive<TableVal>(std::move(s));
} }
DNS_Mgr::AsyncRequest::AsyncRequest(const IPAddr& addr) : addr(addr), type(T_PTR) {}
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////

View file

@ -17,11 +17,14 @@
// those headers here and create install dependencies on them. // those headers here and create install dependencies on them.
struct ares_channeldata; struct ares_channeldata;
using ares_channel = struct ares_channeldata*; using ares_channel = struct ares_channeldata*;
#ifndef T_PTR #ifndef T_PTR
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define T_PTR 12 #define T_PTR 12
#endif #endif
#ifndef T_TXT #ifndef T_TXT
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define T_TXT 16 #define T_TXT 16
#endif #endif
@ -320,7 +323,7 @@ protected:
bool processed = false; bool processed = false;
AsyncRequest(std::string host, int request_type) : host(std::move(host)), type(request_type) {} AsyncRequest(std::string host, int request_type) : host(std::move(host)), type(request_type) {}
AsyncRequest(const IPAddr& addr) : addr(addr), type(T_PTR) {} AsyncRequest(const IPAddr& addr);
void Resolved(const std::string& name); void Resolved(const std::string& name);
void Resolved(TableValPtr addrs); void Resolved(TableValPtr addrs);

View file

@ -605,4 +605,6 @@ int dbg_cmd_trace(DebugCmd cmd, const vector<string>& args) {
return 0; return 0;
} }
int num_debug_cmds() { return static_cast<int>(g_DebugCmdInfos.size()); }
} // namespace zeek::detail } // namespace zeek::detail

View file

@ -51,7 +51,7 @@ extern DebugCmdInfoQueue g_DebugCmdInfos;
void init_global_dbg_constants(); void init_global_dbg_constants();
#define num_debug_cmds() (static_cast<int>(g_DebugCmdInfos.size())) extern int num_debug_cmds();
// Looks up the info record and returns it; if cmd is not found returns 0. // Looks up the info record and returns it; if cmd is not found returns 0.
const DebugCmdInfo* get_debug_cmd_info(DebugCmd cmd); const DebugCmdInfo* get_debug_cmd_info(DebugCmd cmd);

View file

@ -16,6 +16,7 @@
#include <unistd.h> // Needed to ignore __attribute__((format(printf))) on MSVC #include <unistd.h> // Needed to ignore __attribute__((format(printf))) on MSVC
#endif #endif
// NOLINTBEGIN(cppcoreguidelines-macro-usage)
#define DBG_LOG(stream, ...) \ #define DBG_LOG(stream, ...) \
if ( ::zeek::detail::debug_logger.IsEnabled(stream) ) \ if ( ::zeek::detail::debug_logger.IsEnabled(stream) ) \
::zeek::detail::debug_logger.Log(stream, __VA_ARGS__) ::zeek::detail::debug_logger.Log(stream, __VA_ARGS__)
@ -26,6 +27,7 @@
#define DBG_POP(stream) ::zeek::detail::debug_logger.PopIndent(stream) #define DBG_POP(stream) ::zeek::detail::debug_logger.PopIndent(stream)
#define PLUGIN_DBG_LOG(plugin, ...) ::zeek::detail::debug_logger.Log(plugin, __VA_ARGS__) #define PLUGIN_DBG_LOG(plugin, ...) ::zeek::detail::debug_logger.Log(plugin, __VA_ARGS__)
// NOLINTEND(cppcoreguidelines-macro-usage)
namespace zeek { namespace zeek {
@ -124,9 +126,11 @@ extern DebugLogger debug_logger;
} // namespace zeek } // namespace zeek
#else #else
// NOLINTBEGIN(cppcoreguidelines-macro-usage)
#define DBG_LOG(...) #define DBG_LOG(...)
#define DBG_LOG_VERBOSE(...) #define DBG_LOG_VERBOSE(...)
#define DBG_PUSH(stream) #define DBG_PUSH(stream)
#define DBG_POP(stream) #define DBG_POP(stream)
#define PLUGIN_DBG_LOG(plugin, ...) #define PLUGIN_DBG_LOG(plugin, ...)
// NOLINTEND(cppcoreguidelines-macro-usage)
#endif #endif

View file

@ -790,11 +790,14 @@ public:
int ExpectedCapacity() const { return bucket_capacity; } int ExpectedCapacity() const { return bucket_capacity; }
// Debugging // Debugging
#define DUMPIF(f) \
if ( f ) \
Dump(1)
#ifdef ZEEK_DICT_DEBUG #ifdef ZEEK_DICT_DEBUG
void DumpIfInvalid(bool valid) const {
if ( ! valid ) {
Dump(1);
abort();
}
}
void AssertValid() const { void AssertValid() const {
bool valid = true; bool valid = true;
int n = num_entries; int n = num_entries;
@ -805,8 +808,7 @@ public:
n--; n--;
valid = (n == 0); valid = (n == 0);
ASSERT(valid); DumpIfInvalid(valid);
DUMPIF(! valid);
// entries must clustered together // entries must clustered together
for ( int i = 1; i < Capacity(); i++ ) { for ( int i = 1; i < Capacity(); i++ ) {
@ -815,29 +817,28 @@ public:
if ( table[i - 1].Empty() ) { if ( table[i - 1].Empty() ) {
valid = (table[i].distance == 0); valid = (table[i].distance == 0);
ASSERT(valid); DumpIfInvalid(valid);
DUMPIF(! valid);
} }
else { else {
valid = (table[i].bucket >= table[i - 1].bucket); valid = (table[i].bucket >= table[i - 1].bucket);
ASSERT(valid); DumpIfInvalid(valid);
DUMPIF(! valid);
if ( table[i].bucket == table[i - 1].bucket ) { if ( table[i].bucket == table[i - 1].bucket ) {
valid = (table[i].distance == table[i - 1].distance + 1); valid = (table[i].distance == table[i - 1].distance + 1);
ASSERT(valid); DumpIfInvalid(valid);
DUMPIF(! valid);
} }
else { else {
valid = (table[i].distance <= table[i - 1].distance); valid = (table[i].distance <= table[i - 1].distance);
ASSERT(valid); DumpIfInvalid(valid);
DUMPIF(! valid);
} }
} }
} }
} }
#endif // ZEEK_DICT_DEBUG #endif // ZEEK_DICT_DEBUG
static constexpr size_t DICT_NUM_DISTANCES = 5;
void Dump(int level = 0) const { void Dump(int level = 0) const {
int key_size = 0; int key_size = 0;
for ( int i = 0; i < Capacity(); i++ ) { for ( int i = 0; i < Capacity(); i++ ) {
@ -848,7 +849,6 @@ public:
continue; continue;
} }
#define DICT_NUM_DISTANCES 5
int distances[DICT_NUM_DISTANCES]; int distances[DICT_NUM_DISTANCES];
int max_distance = 0; int max_distance = 0;
DistanceStats(max_distance, distances, DICT_NUM_DISTANCES); DistanceStats(max_distance, distances, DICT_NUM_DISTANCES);
@ -858,9 +858,9 @@ public:
Capacity(), Length(), MaxLength(), (double)Length() / (table ? Capacity() : 1), max_distance, Capacity(), Length(), MaxLength(), (double)Length() / (table ? Capacity() : 1), max_distance,
key_size / (Length() ? Length() : 1), log2_buckets, remaps, remap_end); key_size / (Length() ? Length() : 1), log2_buckets, remaps, remap_end);
if ( Length() > 0 ) { if ( Length() > 0 ) {
for ( int i = 0; i < DICT_NUM_DISTANCES - 1; i++ ) for ( size_t i = 0; i < DICT_NUM_DISTANCES - 1; i++ )
printf("[%d]%2d%% ", i, 100 * distances[i] / Length()); printf("[%zu]%2d%% ", i, 100 * distances[i] / Length());
printf("[%d+]%2d%% ", DICT_NUM_DISTANCES - 1, 100 * distances[DICT_NUM_DISTANCES - 1] / Length()); printf("[%zu+]%2d%% ", DICT_NUM_DISTANCES - 1, 100 * distances[DICT_NUM_DISTANCES - 1] / Length());
} }
else else
printf("\n"); printf("\n");

View file

@ -33,6 +33,7 @@ class FragReassembler;
} }
#ifndef IPPROTO_MOBILITY #ifndef IPPROTO_MOBILITY
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define IPPROTO_MOBILITY 135 #define IPPROTO_MOBILITY 135
#endif #endif

View file

@ -321,6 +321,7 @@ using name_list = PList<char>;
} // namespace zeek } // namespace zeek
// Macro to visit each list element in turn. // Macro to visit each list element in turn.
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define loop_over_list(list, iterator) \ #define loop_over_list(list, iterator) \
int iterator; \ int iterator; \
for ( (iterator) = 0; (iterator) < (list).length(); ++(iterator) ) for ( (iterator) = 0; (iterator) < (list).length(); ++(iterator) )

View file

@ -92,7 +92,9 @@ public:
const detail::Location* expr_location = nullptr) const; const detail::Location* expr_location = nullptr) const;
// Report internal errors. // Report internal errors.
void BadTag(const char* msg, const char* t1 = nullptr, const char* t2 = nullptr) const; [[noreturn]] void BadTag(const char* msg, const char* t1 = nullptr, const char* t2 = nullptr) const;
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define CHECK_TAG(t1, t2, text, tag_to_text_func) \ #define CHECK_TAG(t1, t2, text, tag_to_text_func) \
{ \ { \
if ( (t1) != (t2) ) \ if ( (t1) != (t2) ) \

View file

@ -88,6 +88,8 @@ private:
std::unordered_map<std::string, Factory*> _types; std::unordered_map<std::string, Factory*> _types;
}; };
// NOLINTBEGIN(cppcoreguidelines-macro-usage)
/** /**
* Macro to insert into an OpaqueVal-derived class's declaration. Overrides the "new" serialization methods * Macro to insert into an OpaqueVal-derived class's declaration. Overrides the "new" serialization methods
* DoSerializeData and DoUnserializeData. * DoSerializeData and DoUnserializeData.
@ -100,12 +102,15 @@ private:
const char* OpaqueName() const override { return #T; } \ const char* OpaqueName() const override { return #T; } \
static zeek::OpaqueValPtr OpaqueInstantiate() { return zeek::make_intrusive<T>(); } static zeek::OpaqueValPtr OpaqueInstantiate() { return zeek::make_intrusive<T>(); }
#define __OPAQUE_MERGE(a, b) a##b #define __OPAQUE_MERGE(a, b) a##b
#define __OPAQUE_ID(x) __OPAQUE_MERGE(_opaque, x) #define __OPAQUE_ID(x) __OPAQUE_MERGE(_opaque, x)
/** Macro to insert into an OpaqueVal-derived class's implementation file. */ /** Macro to insert into an OpaqueVal-derived class's implementation file. */
#define IMPLEMENT_OPAQUE_VALUE(T) static zeek::OpaqueMgr::Register<T> __OPAQUE_ID(__LINE__)(#T); #define IMPLEMENT_OPAQUE_VALUE(T) static zeek::OpaqueMgr::Register<T> __OPAQUE_ID(__LINE__)(#T);
// NOLINTEND(cppcoreguidelines-macro-usage)
/** /**
* Base class for all opaque values. Opaque values are types that are managed * Base class for all opaque values. Opaque values are types that are managed
* completely internally, with no further script-level operators provided * completely internally, with no further script-level operators provided

View file

@ -14,6 +14,7 @@ enum TraversalCode : uint8_t {
TC_ABORTSTMT = 2, TC_ABORTSTMT = 2,
}; };
// NOLINTBEGIN(cppcoreguidelines-macro-usage)
#define HANDLE_TC_STMT_PRE(code) \ #define HANDLE_TC_STMT_PRE(code) \
{ \ { \
switch ( code ) { \ switch ( code ) { \
@ -46,4 +47,6 @@ enum TraversalCode : uint8_t {
#define HANDLE_TC_ATTR_PRE(code) HANDLE_TC_STMT_PRE(code) #define HANDLE_TC_ATTR_PRE(code) HANDLE_TC_STMT_PRE(code)
#define HANDLE_TC_ATTR_POST(code) return (code); #define HANDLE_TC_ATTR_POST(code) return (code);
// NOLINTEND(cppcoreguidelines-macro-usage)
} // namespace zeek::detail } // namespace zeek::detail

View file

@ -157,6 +157,7 @@ public:
return cast_intrusive<T>(type); return cast_intrusive<T>(type);
} }
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define UNDERLYING_ACCESSOR_DECL(ztype, ctype, name) ctype name() const; #define UNDERLYING_ACCESSOR_DECL(ztype, ctype, name) ctype name() const;
UNDERLYING_ACCESSOR_DECL(detail::IntValImplementation, zeek_int_t, AsInt) UNDERLYING_ACCESSOR_DECL(detail::IntValImplementation, zeek_int_t, AsInt)
@ -433,12 +434,12 @@ public:
// Same as for IntVal: no Get() method needed. // Same as for IntVal: no Get() method needed.
}; };
#define Microseconds 1e-6 constexpr double Microseconds = 1e-6;
#define Milliseconds 1e-3 constexpr double Milliseconds = 1e-3;
#define Seconds 1.0 constexpr double Seconds = 1.0;
#define Minutes (60 * Seconds) constexpr double Minutes = (60 * Seconds);
#define Hours (60 * Minutes) constexpr double Hours = (60 * Minutes);
#define Days (24 * Hours) constexpr double Days = (24 * Hours);
class IntervalVal final : public detail::DoubleValImplementation { class IntervalVal final : public detail::DoubleValImplementation {
public: public:
@ -1717,6 +1718,7 @@ private:
std::vector<TypePtr>* yield_types = nullptr; std::vector<TypePtr>* yield_types = nullptr;
}; };
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define UNDERLYING_ACCESSOR_DEF(ztype, ctype, name) \ #define UNDERLYING_ACCESSOR_DEF(ztype, ctype, name) \
inline ctype Val::name() const { return static_cast<const ztype*>(this)->Get(); } inline ctype Val::name() const { return static_cast<const ztype*>(this)->Get(); }

View file

@ -772,6 +772,8 @@ private:
static ID id_counter; static ID id_counter;
}; };
// NOLINTBEGIN(cppcoreguidelines-macro-usage)
/** /**
* Convenience macro to add a new timer. * Convenience macro to add a new timer.
*/ */
@ -802,6 +804,8 @@ private:
#define LOOP_OVER_GIVEN_CONST_CHILDREN(var, the_kids) \ #define LOOP_OVER_GIVEN_CONST_CHILDREN(var, the_kids) \
for ( auto(var) = (the_kids).cbegin(); (var) != (the_kids).cend(); ++(var) ) for ( auto(var) = (the_kids).cbegin(); (var) != (the_kids).cend(); ++(var) )
// NOLINTEND(cppcoreguidelines-macro-usage)
/** /**
* Support analyzer preprocess input before it reaches an analyzer's main * Support analyzer preprocess input before it reaches an analyzer's main
* processing. They share the input interface with of an Analyzer but they * processing. They share the input interface with of an Analyzer but they
@ -893,9 +897,21 @@ private:
}; };
// The following need to be consistent with zeek.init. // The following need to be consistent with zeek.init.
#define CONTENTS_NONE 0 constexpr int CONTENTS_NONE = 0;
#define CONTENTS_ORIG 1 constexpr int CONTENTS_ORIG = 1;
#define CONTENTS_RESP 2 constexpr int CONTENTS_RESP = 2;
#define CONTENTS_BOTH 3 constexpr int CONTENTS_BOTH = 3;
} // namespace zeek::analyzer } // namespace zeek::analyzer
[[deprecated("Remove in v8.1. Use version in zeek::analyzer namespace.")]] constexpr int CONTENTS_NONE =
zeek::analyzer::CONTENTS_NONE;
[[deprecated("Remove in v8.1. Use version in zeek::analyzer namespace.")]] constexpr int CONTENTS_ORIG =
zeek::analyzer::CONTENTS_ORIG;
[[deprecated("Remove in v8.1. Use version in zeek::analyzer namespace.")]] constexpr int CONTENTS_RESP =
zeek::analyzer::CONTENTS_RESP;
[[deprecated("Remove in v8.1. Use version in zeek::analyzer namespace.")]] constexpr int CONTENTS_BOTH =
zeek::analyzer::CONTENTS_BOTH;

View file

@ -386,6 +386,7 @@ extern analyzer::Manager* analyzer_mgr;
// Macros for analyzer debug logging which include the connection id into the // Macros for analyzer debug logging which include the connection id into the
// message. // message.
// NOLINTBEGIN(cppcoreguidelines-macro-usage)
#ifdef DEBUG #ifdef DEBUG
#define DBG_ANALYZER(conn, txt) \ #define DBG_ANALYZER(conn, txt) \
DBG_LOG(zeek::DBG_ANALYZER, "%s " txt, \ DBG_LOG(zeek::DBG_ANALYZER, "%s " txt, \
@ -399,3 +400,4 @@ extern analyzer::Manager* analyzer_mgr;
#define DBG_ANALYZER(conn, txt) #define DBG_ANALYZER(conn, txt)
#define DBG_ANALYZER_ARGS(conn, fmt, ...) #define DBG_ANALYZER_ARGS(conn, fmt, ...)
#endif #endif
// NOLINTEND(cppcoreguidelines-macro-usage)

View file

@ -16,11 +16,11 @@ namespace zeek::analyzer::ftp {
FTP_Analyzer::FTP_Analyzer(Connection* conn) : analyzer::tcp::TCP_ApplicationAnalyzer("FTP", conn) { FTP_Analyzer::FTP_Analyzer(Connection* conn) : analyzer::tcp::TCP_ApplicationAnalyzer("FTP", conn) {
nvt_orig = new analyzer::login::NVT_Analyzer(conn, true); nvt_orig = new analyzer::login::NVT_Analyzer(conn, true);
nvt_orig->SetIsNULSensitive(true); nvt_orig->SetIsNULSensitive(true);
nvt_orig->SetCRLFAsEOL(LF_as_EOL); nvt_orig->SetCRLFAsEOL(tcp::LF_as_EOL);
nvt_resp = new analyzer::login::NVT_Analyzer(conn, false); nvt_resp = new analyzer::login::NVT_Analyzer(conn, false);
nvt_resp->SetIsNULSensitive(true); nvt_resp->SetIsNULSensitive(true);
nvt_resp->SetCRLFAsEOL(LF_as_EOL); nvt_resp->SetCRLFAsEOL(tcp::LF_as_EOL);
nvt_resp->SetPeer(nvt_orig); nvt_resp->SetPeer(nvt_orig);
nvt_orig->SetPeer(nvt_resp); nvt_orig->SetPeer(nvt_resp);

View file

@ -14,10 +14,14 @@ enum login_state : uint8_t {
}; };
// If no action by this many lines, we're definitely confused. // If no action by this many lines, we're definitely confused.
#define MAX_AUTHENTICATE_LINES 50 constexpr int MAX_AUTHENTICATE_LINES = 50;
// Maximum # lines look after login for failure. // Maximum # lines look after login for failure.
#define MAX_LOGIN_LOOKAHEAD 10 constexpr int MAX_LOGIN_LOOKAHEAD = 10;
// If we have more user text than this unprocessed, we complain about
// excessive typeahead.
constexpr int MAX_USER_TEXT = 12;
class Login_Analyzer : public analyzer::tcp::TCP_ApplicationAnalyzer { class Login_Analyzer : public analyzer::tcp::TCP_ApplicationAnalyzer {
public: public:
@ -61,9 +65,6 @@ protected:
bool HaveTypeahead() const { return num_user_text > 0; } bool HaveTypeahead() const { return num_user_text > 0; }
void FlushEmptyTypeahead(); void FlushEmptyTypeahead();
// If we have more user text than this unprocessed, we complain about
// excessive typeahead.
#define MAX_USER_TEXT 12
char* user_text[MAX_USER_TEXT] = {nullptr}; char* user_text[MAX_USER_TEXT] = {nullptr};
int user_text_first, user_text_last; // indices into user_text int user_text_first, user_text_last; // indices into user_text
int num_user_text; // number of entries in user_text int num_user_text; // number of entries in user_text

View file

@ -412,7 +412,7 @@ void NVT_Analyzer::DeliverChunk(int& len, const u_char*& data) {
switch ( c ) { switch ( c ) {
case '\r': case '\r':
if ( CRLFAsEOL() & CR_as_EOL ) { if ( CRLFAsEOL() & tcp::CR_as_EOL ) {
buf[offset] = '\0'; buf[offset] = '\0';
ForwardStream(offset, buf, IsOrig()); ForwardStream(offset, buf, IsOrig());
offset = 0; offset = 0;
@ -423,7 +423,7 @@ void NVT_Analyzer::DeliverChunk(int& len, const u_char*& data) {
case '\n': case '\n':
if ( last_char == '\r' ) { if ( last_char == '\r' ) {
if ( CRLFAsEOL() & CR_as_EOL ) if ( CRLFAsEOL() & tcp::CR_as_EOL )
// we already emitted, skip // we already emitted, skip
; ;
else { else {
@ -434,7 +434,7 @@ void NVT_Analyzer::DeliverChunk(int& len, const u_char*& data) {
} }
} }
else if ( CRLFAsEOL() & LF_as_EOL ) { else if ( CRLFAsEOL() & tcp::LF_as_EOL ) {
buf[offset] = '\0'; buf[offset] = '\0';
ForwardStream(offset, buf, IsOrig()); ForwardStream(offset, buf, IsOrig());
offset = 0; offset = 0;
@ -474,7 +474,7 @@ void NVT_Analyzer::DeliverChunk(int& len, const u_char*& data) {
default: buf[offset++] = c; break; default: buf[offset++] = c; break;
} }
if ( ! (CRLFAsEOL() & CR_as_EOL) && last_char == '\r' && c != '\n' && c != '\0' ) { if ( ! (CRLFAsEOL() & tcp::CR_as_EOL) && last_char == '\r' && c != '\n' && c != '\0' ) {
if ( Conn()->FlagEvent(SINGULAR_CR) ) if ( Conn()->FlagEvent(SINGULAR_CR) )
Weird("line_terminated_with_single_CR"); Weird("line_terminated_with_single_CR");
} }

View file

@ -30,10 +30,10 @@ namespace analyzer::mime {
// MIME Constants // MIME Constants
#define HT '\011' constexpr char HT = '\011';
#define SP '\040' constexpr char SP = '\040';
#define CR '\015' constexpr char CR = '\015';
#define LF '\012' constexpr char LF = '\012';
enum MIME_CONTENT_TYPE : uint8_t { enum MIME_CONTENT_TYPE : uint8_t {
CONTENT_TYPE_MULTIPART, CONTENT_TYPE_MULTIPART,

View file

@ -69,7 +69,7 @@ protected:
size_t buf_len; // size off msg_buf size_t buf_len; // size off msg_buf
}; };
#define NCP_TCPIP_HEADER_LENGTH 8 constexpr int NCP_TCPIP_HEADER_LENGTH = 8;
class NCP_FrameBuffer : public FrameBuffer { class NCP_FrameBuffer : public FrameBuffer {
public: public:

View file

@ -8,8 +8,8 @@
namespace zeek::analyzer::tcp { namespace zeek::analyzer::tcp {
#define CR_as_EOL 1 constexpr int CR_as_EOL = 1;
#define LF_as_EOL 2 constexpr int LF_as_EOL = 2;
// Slightly smaller than 16MB so that the buffer is not unnecessarily resized to 32M. // Slightly smaller than 16MB so that the buffer is not unnecessarily resized to 32M.
constexpr auto DEFAULT_MAX_LINE_LENGTH = 16 * 1024 * 1024 - 100; constexpr auto DEFAULT_MAX_LINE_LENGTH = 16 * 1024 * 1024 - 100;
@ -122,3 +122,9 @@ protected:
}; };
} // namespace zeek::analyzer::tcp } // namespace zeek::analyzer::tcp
// These were previously #defined, so they have to be outside of the namespace.
[[deprecated("Remove in v8.1, use the version in the zeek:::analyzer::tcp namespace")]] constexpr int CR_as_EOL =
zeek::analyzer::tcp::CR_as_EOL;
[[deprecated("Remove in v8.1, use the version in the zeek:::analyzer::tcp namespace")]] constexpr int LF_as_EOL =
zeek::analyzer::tcp::LF_as_EOL;

View file

@ -193,16 +193,19 @@ public:
// Codes used for tracking history. For responders, we shift these // Codes used for tracking history. For responders, we shift these
// over by 16 bits in order to fit both originator and responder // over by 16 bits in order to fit both originator and responder
// into a Connection's hist_seen field. // into a Connection's hist_seen field.
#define HIST_SYN_PKT 0x1 enum HistoryMasks : uint16_t {
#define HIST_FIN_PKT 0x2 HIST_SYN_PKT = 0x1,
#define HIST_RST_PKT 0x4 HIST_FIN_PKT = 0x2,
#define HIST_FIN_RST_PKT 0x8 HIST_RST_PKT = 0x4,
#define HIST_DATA_PKT 0x10 HIST_FIN_RST_PKT = 0x8,
#define HIST_ACK_PKT 0x20 HIST_DATA_PKT = 0x10,
#define HIST_MULTI_FLAG_PKT 0x40 HIST_ACK_PKT = 0x20,
#define HIST_CORRUPT_PKT 0x80 HIST_MULTI_FLAG_PKT = 0x40,
#define HIST_RXMIT 0x100 HIST_CORRUPT_PKT = 0x80,
#define HIST_WIN0 0x200 HIST_RXMIT = 0x100,
HIST_WIN0 = 0x200,
};
// #define HIST_UNKNOWN_PKT 0x400 (do not use - used in Session.h) // #define HIST_UNKNOWN_PKT 0x400 (do not use - used in Session.h)
bool CheckHistory(uint32_t mask, char code); bool CheckHistory(uint32_t mask, char code);
void AddHistory(char code); void AddHistory(char code);
@ -248,10 +251,50 @@ protected:
uint32_t gap_cnt, gap_thresh; uint32_t gap_cnt, gap_thresh;
}; };
#define ENDIAN_UNKNOWN 0 enum EndianTypes : uint8_t {
#define ENDIAN_LITTLE 1 ENDIAN_UNKNOWN = 0,
#define ENDIAN_BIG 2 ENDIAN_LITTLE = 1,
#define ENDIAN_CONFUSED 3 ENDIAN_BIG = 2,
ENDIAN_CONFUSED = 3,
};
} // namespace analyzer::tcp } // namespace analyzer::tcp
} // namespace zeek } // namespace zeek
[[deprecated(
"Remove in v8.1. Use version in zeek::analyzer::tcp::TCP_Endpoint namespace.")]] constexpr int HIST_SYN_PKT =
zeek::analyzer::tcp::TCP_Endpoint::HIST_SYN_PKT;
[[deprecated(
"Remove in v8.1. Use version in zeek::analyzer::tcp::TCP_Endpoint namespace.")]] constexpr int HIST_FIN_PKT =
zeek::analyzer::tcp::TCP_Endpoint::HIST_FIN_PKT;
[[deprecated(
"Remove in v8.1. Use version in zeek::analyzer::tcp::TCP_Endpoint namespace.")]] constexpr int HIST_RST_PKT =
zeek::analyzer::tcp::TCP_Endpoint::HIST_RST_PKT;
[[deprecated(
"Remove in v8.1. Use version in zeek::analyzer::tcp::TCP_Endpoint namespace.")]] constexpr int HIST_FIN_RST_PKT =
zeek::analyzer::tcp::TCP_Endpoint::HIST_FIN_RST_PKT;
[[deprecated(
"Remove in v8.1. Use version in zeek::analyzer::tcp::TCP_Endpoint namespace.")]] constexpr int HIST_DATA_PKT =
zeek::analyzer::tcp::TCP_Endpoint::HIST_DATA_PKT;
[[deprecated(
"Remove in v8.1. Use version in zeek::analyzer::tcp::TCP_Endpoint namespace.")]] constexpr int HIST_ACK_PKT =
zeek::analyzer::tcp::TCP_Endpoint::HIST_ACK_PKT;
[[deprecated(
"Remove in v8.1. Use version in zeek::analyzer::tcp::TCP_Endpoint namespace.")]] constexpr int HIST_MULTI_FLAG_PKT =
zeek::analyzer::tcp::TCP_Endpoint::HIST_MULTI_FLAG_PKT;
[[deprecated(
"Remove in v8.1. Use version in zeek::analyzer::tcp::TCP_Endpoint namespace.")]] constexpr int HIST_CORRUPT_PKT =
zeek::analyzer::tcp::TCP_Endpoint::HIST_CORRUPT_PKT;
[[deprecated("Remove in v8.1. Use version in zeek::analyzer::tcp::TCP_Endpoint namespace.")]] constexpr int HIST_RXMIT =
zeek::analyzer::tcp::TCP_Endpoint::HIST_RXMIT;
[[deprecated("Remove in v8.1. Use version in zeek::analyzer::tcp::TCP_Endpoint namespace.")]] constexpr int HIST_WIN0 =
zeek::analyzer::tcp::TCP_Endpoint::HIST_WIN0;

View file

@ -192,16 +192,17 @@ static void update_history(analyzer::tcp::TCP_Flags flags, analyzer::tcp::TCP_En
int bits_set = (flags.SYN() ? 1 : 0) + (flags.FIN() ? 1 : 0) + (flags.RST() ? 1 : 0); int bits_set = (flags.SYN() ? 1 : 0) + (flags.FIN() ? 1 : 0) + (flags.RST() ? 1 : 0);
if ( bits_set > 1 ) { if ( bits_set > 1 ) {
if ( flags.FIN() && flags.RST() ) if ( flags.FIN() && flags.RST() )
endpoint->CheckHistory(HIST_FIN_RST_PKT, 'I'); endpoint->CheckHistory(analyzer::tcp::TCP_Endpoint::HIST_FIN_RST_PKT, 'I');
else else
endpoint->CheckHistory(HIST_MULTI_FLAG_PKT, 'Q'); endpoint->CheckHistory(analyzer::tcp::TCP_Endpoint::HIST_MULTI_FLAG_PKT, 'Q');
} }
else if ( bits_set == 1 ) { else if ( bits_set == 1 ) {
if ( flags.SYN() ) { if ( flags.SYN() ) {
char code = flags.ACK() ? 'H' : 'S'; char code = flags.ACK() ? 'H' : 'S';
if ( endpoint->CheckHistory(HIST_SYN_PKT, code) && rel_seq != endpoint->hist_last_SYN ) if ( endpoint->CheckHistory(analyzer::tcp::TCP_Endpoint::HIST_SYN_PKT, code) &&
rel_seq != endpoint->hist_last_SYN )
endpoint->AddHistory(code); endpoint->AddHistory(code);
endpoint->hist_last_SYN = rel_seq; endpoint->hist_last_SYN = rel_seq;
@ -211,14 +212,16 @@ static void update_history(analyzer::tcp::TCP_Flags flags, analyzer::tcp::TCP_En
// For FIN's, the sequence number comes at the // For FIN's, the sequence number comes at the
// end of (any data in) the packet, not the // end of (any data in) the packet, not the
// beginning as for SYNs and RSTs. // beginning as for SYNs and RSTs.
if ( endpoint->CheckHistory(HIST_FIN_PKT, 'F') && rel_seq + len != endpoint->hist_last_FIN ) if ( endpoint->CheckHistory(analyzer::tcp::TCP_Endpoint::HIST_FIN_PKT, 'F') &&
rel_seq + len != endpoint->hist_last_FIN )
endpoint->AddHistory('F'); endpoint->AddHistory('F');
endpoint->hist_last_FIN = rel_seq + len; endpoint->hist_last_FIN = rel_seq + len;
} }
if ( flags.RST() ) { if ( flags.RST() ) {
if ( endpoint->CheckHistory(HIST_RST_PKT, 'R') && rel_seq != endpoint->hist_last_RST ) if ( endpoint->CheckHistory(analyzer::tcp::TCP_Endpoint::HIST_RST_PKT, 'R') &&
rel_seq != endpoint->hist_last_RST )
endpoint->AddHistory('R'); endpoint->AddHistory('R');
endpoint->hist_last_RST = rel_seq; endpoint->hist_last_RST = rel_seq;
@ -227,10 +230,10 @@ static void update_history(analyzer::tcp::TCP_Flags flags, analyzer::tcp::TCP_En
else { // bits_set == 0 else { // bits_set == 0
if ( len ) if ( len )
endpoint->CheckHistory(HIST_DATA_PKT, 'D'); endpoint->CheckHistory(analyzer::tcp::TCP_Endpoint::HIST_DATA_PKT, 'D');
else if ( flags.ACK() ) else if ( flags.ACK() )
endpoint->CheckHistory(HIST_ACK_PKT, 'A'); endpoint->CheckHistory(analyzer::tcp::TCP_Endpoint::HIST_ACK_PKT, 'A');
} }
} }
@ -1142,28 +1145,28 @@ void TCPSessionAdapter::DeleteTimer(double /* t */) { session_mgr->Remove(Conn()
void TCPSessionAdapter::ConnDeleteTimer(double t) { Conn()->DeleteTimer(t); } void TCPSessionAdapter::ConnDeleteTimer(double t) { Conn()->DeleteTimer(t); }
void TCPSessionAdapter::SetContentsFile(unsigned int direction, FilePtr f) { void TCPSessionAdapter::SetContentsFile(unsigned int direction, FilePtr f) {
if ( direction == CONTENTS_NONE ) { if ( direction == analyzer::CONTENTS_NONE ) {
orig->SetContentsFile(nullptr); orig->SetContentsFile(nullptr);
resp->SetContentsFile(nullptr); resp->SetContentsFile(nullptr);
} }
else { else {
if ( direction == CONTENTS_ORIG || direction == CONTENTS_BOTH ) if ( direction == analyzer::CONTENTS_ORIG || direction == analyzer::CONTENTS_BOTH )
orig->SetContentsFile(f); orig->SetContentsFile(f);
if ( direction == CONTENTS_RESP || direction == CONTENTS_BOTH ) if ( direction == analyzer::CONTENTS_RESP || direction == analyzer::CONTENTS_BOTH )
resp->SetContentsFile(f); resp->SetContentsFile(f);
} }
} }
FilePtr TCPSessionAdapter::GetContentsFile(unsigned int direction) const { FilePtr TCPSessionAdapter::GetContentsFile(unsigned int direction) const {
switch ( direction ) { switch ( direction ) {
case CONTENTS_NONE: return nullptr; case analyzer::CONTENTS_NONE: return nullptr;
case CONTENTS_ORIG: return orig->GetContentsFile(); case analyzer::CONTENTS_ORIG: return orig->GetContentsFile();
case CONTENTS_RESP: return resp->GetContentsFile(); case analyzer::CONTENTS_RESP: return resp->GetContentsFile();
case CONTENTS_BOTH: case analyzer::CONTENTS_BOTH:
if ( orig->GetContentsFile() != resp->GetContentsFile() ) if ( orig->GetContentsFile() != resp->GetContentsFile() )
// This is an "error". // This is an "error".
return nullptr; return nullptr;

View file

@ -33,6 +33,7 @@ namespace plugin {
* *
* @param method_call The \a Manager method corresponding to the hook. * @param method_call The \a Manager method corresponding to the hook.
*/ */
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define PLUGIN_HOOK_VOID(hook, method_call) \ #define PLUGIN_HOOK_VOID(hook, method_call) \
{ \ { \
if ( zeek::plugin_mgr->HavePluginForHook(zeek::plugin::hook) ) \ if ( zeek::plugin_mgr->HavePluginForHook(zeek::plugin::hook) ) \
@ -49,6 +50,7 @@ namespace plugin {
* @param default_result: The result to use if there's no plugin implementing * @param default_result: The result to use if there's no plugin implementing
* the hook. * the hook.
*/ */
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define PLUGIN_HOOK_WITH_RESULT(hook, method_call, default_result) \ #define PLUGIN_HOOK_WITH_RESULT(hook, method_call, default_result) \
(zeek::plugin_mgr->HavePluginForHook(zeek::plugin::hook) ? zeek::plugin_mgr->method_call : (default_result)) (zeek::plugin_mgr->HavePluginForHook(zeek::plugin::hook) ? zeek::plugin_mgr->method_call : (default_result))

View file

@ -653,12 +653,12 @@ F RET_CONST(zeek::val_mgr->False()->Ref())
RET_CONST(zeek::val_mgr->Port(p, TRANSPORT_UNKNOWN)->Ref()) RET_CONST(zeek::val_mgr->Port(p, TRANSPORT_UNKNOWN)->Ref())
} }
{FLOAT}{OWS}day(s?) RET_CONST(new zeek::IntervalVal(atof(yytext),Days)) {FLOAT}{OWS}day(s?) RET_CONST(new zeek::IntervalVal(atof(yytext), zeek::Days))
{FLOAT}{OWS}hr(s?) RET_CONST(new zeek::IntervalVal(atof(yytext),Hours)) {FLOAT}{OWS}hr(s?) RET_CONST(new zeek::IntervalVal(atof(yytext), zeek::Hours))
{FLOAT}{OWS}min(s?) RET_CONST(new zeek::IntervalVal(atof(yytext),Minutes)) {FLOAT}{OWS}min(s?) RET_CONST(new zeek::IntervalVal(atof(yytext), zeek::Minutes))
{FLOAT}{OWS}sec(s?) RET_CONST(new zeek::IntervalVal(atof(yytext),Seconds)) {FLOAT}{OWS}sec(s?) RET_CONST(new zeek::IntervalVal(atof(yytext), zeek::Seconds))
{FLOAT}{OWS}msec(s?) RET_CONST(new zeek::IntervalVal(atof(yytext),Milliseconds)) {FLOAT}{OWS}msec(s?) RET_CONST(new zeek::IntervalVal(atof(yytext), zeek::Milliseconds))
{FLOAT}{OWS}usec(s?) RET_CONST(new zeek::IntervalVal(atof(yytext),Microseconds)) {FLOAT}{OWS}usec(s?) RET_CONST(new zeek::IntervalVal(atof(yytext), zeek::Microseconds))
"0x"{HEX}+ RET_CONST(zeek::val_mgr->Count(static_cast<zeek_uint_t>(strtoull(yytext, 0, 16))).release()) "0x"{HEX}+ RET_CONST(zeek::val_mgr->Count(static_cast<zeek_uint_t>(strtoull(yytext, 0, 16))).release())

View file

@ -326,4 +326,5 @@ protected:
} // namespace session } // namespace session
} // namespace zeek } // namespace zeek
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define ADD_TIMER(timer, t, do_expire, type) AddTimer(timer_func(timer), (t), (do_expire), (type)) #define ADD_TIMER(timer, t, do_expire, type) AddTimer(timer_func(timer), (t), (do_expire), (type))

View file

@ -23,6 +23,7 @@
// Macro helper to report Spicy debug messages. This forwards to // Macro helper to report Spicy debug messages. This forwards to
// to both the Zeek logger and the Spicy runtime logger. // to both the Zeek logger and the Spicy runtime logger.
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define SPICY_DEBUG(msg) ::zeek::spicy::log(msg); #define SPICY_DEBUG(msg) ::zeek::spicy::log(msg);
namespace hilti::rt { namespace hilti::rt {

View file

@ -56,7 +56,8 @@ inline const auto CxxZeekIncludesDirectories() {
return includes; return includes;
} }
// Version of Spicy that we are compiling against. // Version of Spicy that we are compiling against. Used for codegen changes in glue-compiler.cc.
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#cmakedefine SPICY_VERSION_NUMBER ${SPICY_VERSION_NUMBER} #cmakedefine SPICY_VERSION_NUMBER ${SPICY_VERSION_NUMBER}
inline const auto InstallPrefix = path("${CMAKE_INSTALL_PREFIX}"); inline const auto InstallPrefix = path("${CMAKE_INSTALL_PREFIX}");

View file

@ -1146,28 +1146,19 @@ function find_first%(str: string, re: pattern%) : string
function hexdump%(data_str: string%) : string function hexdump%(data_str: string%) : string
%{ %{
// The width of a line of text in the hex-mode view, consisting // The width of a line of text in the hex-mode view, consisting
// of offset, hex view and ASCII view: // of offset, hex view and ASCII view:
// //
// 32 + 16 characters per 8 bytes, twice // 32 + 16 characters per 8 bytes, twice
// (2*7) + Single space between bytes, twice // (2*7) + Single space between bytes, twice
// 4 + Two spaces between 8-byte sets and ASCII // 4 + Two spaces between 8-byte sets and ASCII
// 1 + For newline // 1 + For newline
// 17 + For ASCII display, with spacer column // 17 + For ASCII display, with spacer column
// 6 For 5-digit offset counter, including spacer // 6 For 5-digit offset counter, including spacer
// //
#define HEX_LINE_WIDTH 74 constexpr int HEX_LINE_WIDTH = 74;
constexpr char NULL_CHAR = '.';
#define HEX_LINE_START 6 constexpr char NONPRINT_CHAR = '.';
#define HEX_LINE_END 53
#define HEX_LINE_START_ASCII 56
#define HEX_LINE_START_RIGHT_ASCII 65
#define HEX_LINE_LEFT_MIDDLE 28
#define HEX_LINE_RIGHT_MIDDLE 31
#define HEX_BLOCK_LEN 23
#define HEX_LINE_BYTES 16
constexpr char NULL_CHAR = '.';
constexpr char NONPRINT_CHAR = '.';
const u_char* data = data_str->Bytes(); const u_char* data = data_str->Bytes();
unsigned data_size = data_str->Len(); unsigned data_size = data_str->Len();

View file

@ -38,6 +38,7 @@
#include <cassert> #include <cassert>
// NOLINTBEGIN(cppcoreguidelines-macro-usage)
#ifdef ASSERT #ifdef ASSERT
#undef ASSERT #undef ASSERT
#endif #endif
@ -55,6 +56,7 @@
#define DEBUG_fputs(...) #define DEBUG_fputs(...)
#endif #endif
// NOLINTEND(cppcoreguidelines-macro-usage)
#ifdef USE_PERFTOOLS_DEBUG #ifdef USE_PERFTOOLS_DEBUG
#include <gperftools/heap-checker.h> #include <gperftools/heap-checker.h>
@ -101,6 +103,10 @@ extern char* strcasestr(const char* s, const char* find);
// This is used by the patricia code and so it remains outside of the namespace. // This is used by the patricia code and so it remains outside of the namespace.
extern "C" void out_of_memory(const char* where); extern "C" void out_of_memory(const char* where);
constexpr int UID_POOL_DEFAULT_INTERNAL = 1;
constexpr int UID_POOL_DEFAULT_SCRIPT = 2;
constexpr int UID_POOL_CUSTOM_SCRIPT = 10; // First available custom script level pool.
namespace zeek { namespace zeek {
class ODesc; class ODesc;
@ -408,9 +414,6 @@ extern double curr_CPU_time();
// instances. The integer can be drawn from different pools, which is helpful // instances. The integer can be drawn from different pools, which is helpful
// when the random number generator is seeded to be deterministic. In that // when the random number generator is seeded to be deterministic. In that
// case, the same sequence of integers is generated per pool. // case, the same sequence of integers is generated per pool.
#define UID_POOL_DEFAULT_INTERNAL 1
#define UID_POOL_DEFAULT_SCRIPT 2
#define UID_POOL_CUSTOM_SCRIPT 10 // First available custom script level pool.
extern uint64_t calculate_unique_id(); extern uint64_t calculate_unique_id();
extern uint64_t calculate_unique_id(const size_t pool); extern uint64_t calculate_unique_id(const size_t pool);
@ -432,7 +435,13 @@ constexpr size_t pad_size(size_t size) {
return ((size + 3) / pad + 1) * pad; return ((size + 3) / pad + 1) * pad;
} }
#define padded_sizeof(x) (zeek::util::pad_size(sizeof(x))) template<typename T>
constexpr size_t padded_size_of() {
return zeek::util::pad_size(sizeof(T));
}
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define padded_sizeof(x) (zeek::util::padded_size_of<decltype((x))>())
// Like write() but handles interrupted system calls by restarting. Returns // Like write() but handles interrupted system calls by restarting. Returns
// true if the write was successful, otherwise sets errno. This function is // true if the write was successful, otherwise sets errno. This function is