The Great Embooleanating

A large number of functions had return values and/or arguments changed
to use ``bool`` types instead of ``int``.
This commit is contained in:
Tim Wojtulewicz 2020-03-11 10:41:46 -07:00 committed by Robin Sommer
parent 3c470ffe13
commit fd5e15b116
145 changed files with 1288 additions and 1331 deletions

6
NEWS
View file

@ -39,6 +39,12 @@ Changed Functionality
detected and used at configuration-time. Use the ``--enable-rocksdb`` and detected and used at configuration-time. Use the ``--enable-rocksdb`` and
``--with-rocksdb=`` flags to opt-in. ``--with-rocksdb=`` flags to opt-in.
- A large number of functions had return values and/or arguments changed
to use ``bool`` types instead of ``int``. This includes some virtual
methods, which may cause build failures in plugins that were overriding
those methods. Those plugins will need to be updated to match these API
changes.
Removed Functionality Removed Functionality
--------------------- ---------------------

View file

@ -69,13 +69,13 @@ ipaddr32_t AnonymizeIPAddr::Anonymize(ipaddr32_t addr)
} }
// Keep the specified prefix unchanged. // Keep the specified prefix unchanged.
int AnonymizeIPAddr::PreservePrefix(ipaddr32_t /* input */, int /* num_bits */) bool AnonymizeIPAddr::PreservePrefix(ipaddr32_t /* input */, int /* num_bits */)
{ {
reporter->InternalError("prefix preserving is not supported for the anonymizer"); reporter->InternalError("prefix preserving is not supported for the anonymizer");
return 0; return false;
} }
int AnonymizeIPAddr::PreserveNet(ipaddr32_t input) bool AnonymizeIPAddr::PreserveNet(ipaddr32_t input)
{ {
switch ( addr_to_class(ntohl(input)) ) { switch ( addr_to_class(ntohl(input)) ) {
case 'A': case 'A':
@ -85,7 +85,7 @@ int AnonymizeIPAddr::PreserveNet(ipaddr32_t input)
case 'C': case 'C':
return PreservePrefix(input, 24); return PreservePrefix(input, 24);
default: default:
return 0; return false;
} }
} }
@ -160,7 +160,7 @@ void AnonymizeIPAddr_A50::init()
new_mapping = 0; new_mapping = 0;
} }
int AnonymizeIPAddr_A50::PreservePrefix(ipaddr32_t input, int num_bits) bool AnonymizeIPAddr_A50::PreservePrefix(ipaddr32_t input, int num_bits)
{ {
DEBUG_MSG("%s/%d\n", DEBUG_MSG("%s/%d\n",
IPAddr(IPv4, &input, IPAddr::Network).AsString().c_str(), IPAddr(IPv4, &input, IPAddr::Network).AsString().c_str(),
@ -169,7 +169,7 @@ int AnonymizeIPAddr_A50::PreservePrefix(ipaddr32_t input, int num_bits)
if ( ! before_anonymization ) if ( ! before_anonymization )
{ {
reporter->Error("prefix perservation specified after anonymization begun"); reporter->Error("prefix perservation specified after anonymization begun");
return 0; return false;
} }
input = ntohl(input); input = ntohl(input);
@ -191,7 +191,7 @@ int AnonymizeIPAddr_A50::PreservePrefix(ipaddr32_t input, int num_bits)
n->output = (input & prefix_mask) | (rand32() & suffix_mask); n->output = (input & prefix_mask) | (rand32() & suffix_mask);
} }
return 1; return true;
} }
ipaddr32_t AnonymizeIPAddr_A50::anonymize(ipaddr32_t a) ipaddr32_t AnonymizeIPAddr_A50::anonymize(ipaddr32_t a)

View file

@ -44,11 +44,11 @@ public:
ipaddr32_t Anonymize(ipaddr32_t addr); ipaddr32_t Anonymize(ipaddr32_t addr);
virtual int PreservePrefix(ipaddr32_t input, int num_bits); virtual bool PreservePrefix(ipaddr32_t input, int num_bits);
virtual ipaddr32_t anonymize(ipaddr32_t addr) = 0; virtual ipaddr32_t anonymize(ipaddr32_t addr) = 0;
int PreserveNet(ipaddr32_t input); bool PreserveNet(ipaddr32_t input);
protected: protected:
map<ipaddr32_t, ipaddr32_t> mapping; map<ipaddr32_t, ipaddr32_t> mapping;
@ -85,7 +85,7 @@ public:
~AnonymizeIPAddr_A50() override; ~AnonymizeIPAddr_A50() override;
ipaddr32_t anonymize(ipaddr32_t addr) override; ipaddr32_t anonymize(ipaddr32_t addr) override;
int PreservePrefix(ipaddr32_t input, int num_bits) override; bool PreservePrefix(ipaddr32_t input, int num_bits) override;
protected: protected:
struct Node { struct Node {

View file

@ -104,7 +104,7 @@ void Attr::DescribeReST(ODesc* d, bool shorten) const
else if ( expr->Tag() == EXPR_CONST ) else if ( expr->Tag() == EXPR_CONST )
{ {
ODesc dd; ODesc dd;
dd.SetQuotes(1); dd.SetQuotes(true);
expr->Describe(&dd); expr->Describe(&dd);
string s = dd.Description(); string s = dd.Description();
add_long_expr_string(d, s, shorten); add_long_expr_string(d, s, shorten);
@ -260,7 +260,7 @@ void Attributes::CheckAttr(Attr* a)
case ATTR_ADD_FUNC: case ATTR_ADD_FUNC:
case ATTR_DEL_FUNC: case ATTR_DEL_FUNC:
{ {
int is_add = a->Tag() == ATTR_ADD_FUNC; bool is_add = a->Tag() == ATTR_ADD_FUNC;
BroType* at = a->AttrExpr()->Type(); BroType* at = a->AttrExpr()->Type();
if ( at->Tag() != TYPE_FUNC ) if ( at->Tag() != TYPE_FUNC )
@ -635,4 +635,3 @@ bool Attributes::operator==(const Attributes& other) const
return true; return true;
} }

View file

@ -138,7 +138,7 @@ int Base64Converter::Decode(int len, const char* data, int* pblen, char** pbuf)
int dlen = 0; int dlen = 0;
while ( 1 ) while ( true )
{ {
if ( base64_group_next == 4 ) if ( base64_group_next == 4 )
{ {
@ -255,7 +255,7 @@ BroString* decode_base64(const BroString* s, const BroString* a, Connection* con
rlen += rlen2; rlen += rlen2;
rbuf[rlen] = '\0'; rbuf[rlen] = '\0';
return new BroString(1, (u_char*) rbuf, rlen); return new BroString(true, (u_char*) rbuf, rlen);
err: err:
delete [] rbuf; delete [] rbuf;
@ -276,5 +276,5 @@ BroString* encode_base64(const BroString* s, const BroString* a, Connection* con
Base64Converter enc(conn, a ? a->CheckString() : ""); Base64Converter enc(conn, a ? a->CheckString() : "");
enc.Encode(s->Len(), (const unsigned char*) s->Bytes(), &outlen, &outbuf); enc.Encode(s->Len(), (const unsigned char*) s->Bytes(), &outlen, &outbuf);
return new BroString(1, (u_char*)outbuf, outlen); return new BroString(true, (u_char*)outbuf, outlen);
} }

View file

@ -32,7 +32,7 @@ public:
void Encode(int len, const unsigned char* data, int* blen, char** buf); void Encode(int len, const unsigned char* data, int* blen, char** buf);
int Done(int* pblen, char** pbuf); int Done(int* pblen, char** pbuf);
int HasData() const { return base64_group_next != 0; } bool HasData() const { return base64_group_next != 0; }
// True if an error has occurred. // True if an error has occurred.
int Errored() const { return errored; } int Errored() const { return errored; }

View file

@ -107,7 +107,7 @@ void BroString::Adopt(byte_vec bytes, int len)
// Check if the string ends with a NUL. If so, mark it as having // Check if the string ends with a NUL. If so, mark it as having
// a final NUL and adjust the length accordingly. // a final NUL and adjust the length accordingly.
final_NUL = (b[len-1] == '\0') ? 1 : 0; final_NUL = (b[len-1] == '\0');
n = len - final_NUL; n = len - final_NUL;
} }
@ -289,7 +289,7 @@ BroString* BroString::GetSubstring(int start, int len) const
if ( len < 0 || len > n - start ) if ( len < 0 || len > n - start )
len = n - start; len = n - start;
return new BroString(&b[start], len, 1); return new BroString(&b[start], len, true);
} }
int BroString::FindSubstring(const BroString* s) const int BroString::FindSubstring(const BroString* s) const

View file

@ -15,7 +15,7 @@ public:
void Add(int sym); void Add(int sym);
void Negate(); void Negate();
int IsNegated() { return negated; } bool IsNegated() { return negated != 0; }
int Index() { return index; } int Index() { return index; }
void Sort(); void Sort();

View file

@ -25,20 +25,20 @@ CompositeHash::CompositeHash(IntrusivePtr<TypeList> composite_type)
{ {
if ( (*type->Types())[0]->Tag() == TYPE_RECORD ) if ( (*type->Types())[0]->Tag() == TYPE_RECORD )
{ {
is_complex_type = 1; is_complex_type = true;
is_singleton = 0; is_singleton = false;
} }
else else
{ {
is_complex_type = 0; is_complex_type = false;
is_singleton = 1; is_singleton = true;
} }
} }
else else
{ {
is_singleton = 0; is_singleton = false;
is_complex_type = 0; is_complex_type = false;
} }
if ( is_singleton ) if ( is_singleton )
@ -52,7 +52,7 @@ CompositeHash::CompositeHash(IntrusivePtr<TypeList> composite_type)
else else
{ {
size = ComputeKeySize(0, 1, true); size = ComputeKeySize(0, true, true);
if ( size > 0 ) if ( size > 0 )
// Fixed size. Make sure what we get is fully aligned. // Fixed size. Make sure what we get is fully aligned.
@ -69,7 +69,7 @@ CompositeHash::~CompositeHash()
} }
// Computes the piece of the hash for Val*, returning the new kp. // Computes the piece of the hash for Val*, returning the new kp.
char* CompositeHash::SingleValHash(int type_check, char* kp0, char* CompositeHash::SingleValHash(bool type_check, char* kp0,
BroType* bt, Val* v, bool optional) const BroType* bt, Val* v, bool optional) const
{ {
char* kp1 = 0; char* kp1 = 0;
@ -333,7 +333,7 @@ char* CompositeHash::SingleValHash(int type_check, char* kp0,
} }
HashKey* CompositeHash::ComputeHash(const Val* v, int type_check) const HashKey* CompositeHash::ComputeHash(const Val* v, bool type_check) const
{ {
if ( ! v ) if ( ! v )
reporter->InternalError("null value given to CompositeHash::ComputeHash"); reporter->InternalError("null value given to CompositeHash::ComputeHash");
@ -364,7 +364,7 @@ HashKey* CompositeHash::ComputeHash(const Val* v, int type_check) const
return 0; return 0;
k = reinterpret_cast<char*>(new double[sz/sizeof(double) + 1]); k = reinterpret_cast<char*>(new double[sz/sizeof(double) + 1]);
type_check = 0; // no need to type-check again. type_check = false; // no need to type-check again.
} }
const type_list* tl = type->Types(); const type_list* tl = type->Types();
@ -387,7 +387,7 @@ HashKey* CompositeHash::ComputeHash(const Val* v, int type_check) const
return new HashKey((k == key), (void*) k, kp - k); return new HashKey((k == key), (void*) k, kp - k);
} }
HashKey* CompositeHash::ComputeSingletonHash(const Val* v, int type_check) const HashKey* CompositeHash::ComputeSingletonHash(const Val* v, bool type_check) const
{ {
if ( v->Type()->Tag() == TYPE_LIST ) if ( v->Type()->Tag() == TYPE_LIST )
{ {
@ -449,7 +449,7 @@ HashKey* CompositeHash::ComputeSingletonHash(const Val* v, int type_check) const
} }
int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v,
int type_check, int sz, bool optional, bool type_check, int sz, bool optional,
bool calc_static_size) const bool calc_static_size) const
{ {
InternalTypeTag t = bt->InternalType(); InternalTypeTag t = bt->InternalType();
@ -629,7 +629,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v,
return sz; return sz;
} }
int CompositeHash::ComputeKeySize(const Val* v, int type_check, bool calc_static_size) const int CompositeHash::ComputeKeySize(const Val* v, bool type_check, bool calc_static_size) const
{ {
const type_list* tl = type->Types(); const type_list* tl = type->Types();
const val_list* vl = 0; const val_list* vl = 0;
@ -1044,7 +1044,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0,
kp1 = reinterpret_cast<const char*>(kp+1); kp1 = reinterpret_cast<const char*>(kp+1);
} }
*pval = make_intrusive<StringVal>(new BroString((const byte_vec) kp1, n, 1)); *pval = make_intrusive<StringVal>(new BroString((const byte_vec) kp1, n, true));
kp1 += n; kp1 += n;
} }
break; break;

View file

@ -15,7 +15,7 @@ public:
// Compute the hash corresponding to the given index val, // Compute the hash corresponding to the given index val,
// or 0 if it fails to typecheck. // or 0 if it fails to typecheck.
HashKey* ComputeHash(const Val* v, int type_check) const; HashKey* ComputeHash(const Val* v, bool type_check) const;
// Given a hash key, recover the values used to create it. // Given a hash key, recover the values used to create it.
IntrusivePtr<ListVal> RecoverVals(const HashKey* k) const; IntrusivePtr<ListVal> RecoverVals(const HashKey* k) const;
@ -23,11 +23,11 @@ public:
unsigned int MemoryAllocation() const { return padded_sizeof(*this) + pad_size(size); } unsigned int MemoryAllocation() const { return padded_sizeof(*this) + pad_size(size); }
protected: protected:
HashKey* ComputeSingletonHash(const Val* v, int type_check) const; HashKey* ComputeSingletonHash(const Val* v, bool type_check) const;
// Computes the piece of the hash for Val*, returning the new kp. // Computes the piece of the hash for Val*, returning the new kp.
// Used as a helper for ComputeHash in the non-singleton case. // Used as a helper for ComputeHash in the non-singleton case.
char* SingleValHash(int type_check, char* kp, BroType* bt, Val* v, char* SingleValHash(bool type_check, char* kp, BroType* bt, Val* v,
bool optional) const; bool optional) const;
// Recovers just one Val of possibly many; called from RecoverVals. // Recovers just one Val of possibly many; called from RecoverVals.
@ -72,20 +72,20 @@ protected:
// the value is computed for the particular list of values. // the value is computed for the particular list of values.
// Returns 0 if the key has an indeterminant size (if v not given), // Returns 0 if the key has an indeterminant size (if v not given),
// or if v doesn't match the index type (if given). // or if v doesn't match the index type (if given).
int ComputeKeySize(const Val* v, int type_check, int ComputeKeySize(const Val* v, bool type_check,
bool calc_static_size) const; bool calc_static_size) const;
int SingleTypeKeySize(BroType*, const Val*, int SingleTypeKeySize(BroType*, const Val*,
int type_check, int sz, bool optional, bool type_check, int sz, bool optional,
bool calc_static_size) const; bool calc_static_size) const;
IntrusivePtr<TypeList> type; IntrusivePtr<TypeList> type;
char* key; // space for composite key char* key; // space for composite key
int size; int size;
int is_singleton; // if just one type in index bool is_singleton; // if just one type in index
// If one type, but not normal "singleton", e.g. record. // If one type, but not normal "singleton", e.g. record.
int is_complex_type; bool is_complex_type;
InternalTypeTag singleton_tag; InternalTypeTag singleton_tag;
}; };

View file

@ -39,7 +39,7 @@ ConnectionTimer::~ConnectionTimer()
Unref(conn); Unref(conn);
} }
void ConnectionTimer::Dispatch(double t, int is_expire) void ConnectionTimer::Dispatch(double t, bool is_expire)
{ {
if ( is_expire && ! do_expire ) if ( is_expire && ! do_expire )
return; return;
@ -177,7 +177,7 @@ void Connection::Done()
root_analyzer->Done(); root_analyzer->Done();
} }
void Connection::NextPacket(double t, int is_orig, void Connection::NextPacket(double t, bool is_orig,
const IP_Hdr* ip, int len, int caplen, const IP_Hdr* ip, int len, int caplen,
const u_char*& data, const u_char*& data,
int& record_packet, int& record_content, int& record_packet, int& record_content,

View file

@ -87,7 +87,7 @@ public:
// If record_content is true, then its entire contents should // If record_content is true, then its entire contents should
// be recorded, otherwise just up through the transport header. // be recorded, otherwise just up through the transport header.
// Both are assumed set to true when called. // Both are assumed set to true when called.
void NextPacket(double t, int is_orig, void NextPacket(double t, bool is_orig,
const IP_Hdr* ip, int len, int caplen, const IP_Hdr* ip, int len, int caplen,
const u_char*& data, const u_char*& data,
int& record_packet, int& record_content, int& record_packet, int& record_content,
@ -126,27 +126,27 @@ public:
// True if we should record subsequent packets (either headers or // True if we should record subsequent packets (either headers or
// in their entirety, depending on record_contents). We still // in their entirety, depending on record_contents). We still
// record subsequent SYN/FIN/RST, regardless of how this is set. // record subsequent SYN/FIN/RST, regardless of how this is set.
int RecordPackets() const { return record_packets; } bool RecordPackets() const { return record_packets; }
void SetRecordPackets(int do_record) { record_packets = do_record; } void SetRecordPackets(bool do_record) { record_packets = do_record ? 1 : 0; }
// True if we should record full packets for this connection, // True if we should record full packets for this connection,
// false if we should just record headers. // false if we should just record headers.
int RecordContents() const { return record_contents; } bool RecordContents() const { return record_contents; }
void SetRecordContents(int do_record) { record_contents = do_record; } void SetRecordContents(bool do_record) { record_contents = do_record ? 1 : 0; }
// Set whether to record *current* packet header/full. // Set whether to record *current* packet header/full.
void SetRecordCurrentPacket(int do_record) void SetRecordCurrentPacket(bool do_record)
{ record_current_packet = do_record; } { record_current_packet = do_record ? 1 : 0; }
void SetRecordCurrentContent(int do_record) void SetRecordCurrentContent(bool do_record)
{ record_current_content = do_record; } { record_current_content = do_record ? 1 : 0; }
// FIXME: Now this is in Analyzer and should eventually be removed here. // FIXME: Now this is in Analyzer and should eventually be removed here.
// //
// If true, skip processing of remainder of connection. Note // If true, skip processing of remainder of connection. Note
// that this does not in itself imply that record_packets is false; // that this does not in itself imply that record_packets is false;
// we might want instead to process the connection off-line. // we might want instead to process the connection off-line.
void SetSkip(int do_skip) { skip = do_skip; } void SetSkip(bool do_skip) { skip = do_skip ? 1 : 0; }
int Skipping() const { return skip; } bool Skipping() const { return skip; }
// Arrange for the connection to expire after the given amount of time. // Arrange for the connection to expire after the given amount of time.
void SetLifetime(double lifetime); void SetLifetime(double lifetime);
@ -237,16 +237,16 @@ public:
// Cancel all associated timers. // Cancel all associated timers.
void CancelTimers(); void CancelTimers();
inline int FlagEvent(ConnEventToFlag e) inline bool FlagEvent(ConnEventToFlag e)
{ {
if ( e >= 0 && e < NUM_EVENTS_TO_FLAG ) if ( e >= 0 && e < NUM_EVENTS_TO_FLAG )
{ {
if ( suppress_event & (1 << e) ) if ( suppress_event & (1 << e) )
return 0; return false;
suppress_event |= 1 << e; suppress_event |= 1 << e;
} }
return 1; return true;
} }
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
@ -264,7 +264,7 @@ public:
{ return current_connections; } { return current_connections; }
// Returns true if the history was already seen, false otherwise. // Returns true if the history was already seen, false otherwise.
int CheckHistory(uint32_t mask, char code) bool CheckHistory(uint32_t mask, char code)
{ {
if ( (hist_seen & mask) == 0 ) if ( (hist_seen & mask) == 0 )
{ {
@ -387,7 +387,7 @@ public:
{ Init(arg_conn, arg_timer, arg_do_expire); } { Init(arg_conn, arg_timer, arg_do_expire); }
~ConnectionTimer() override; ~ConnectionTimer() override;
void Dispatch(double t, int is_expire) override; void Dispatch(double t, bool is_expire) override;
protected: protected:
ConnectionTimer() {} ConnectionTimer() {}

View file

@ -107,8 +107,8 @@ public:
DNS_Mapping(const IPAddr& addr, struct hostent* h, uint32_t ttl); DNS_Mapping(const IPAddr& addr, struct hostent* h, uint32_t ttl);
DNS_Mapping(FILE* f); DNS_Mapping(FILE* f);
int NoMapping() const { return no_mapping; } bool NoMapping() const { return no_mapping; }
int InitFailed() const { return init_failed; } bool InitFailed() const { return init_failed; }
~DNS_Mapping(); ~DNS_Mapping();
@ -128,8 +128,8 @@ public:
void Save(FILE* f) const; void Save(FILE* f) const;
int Failed() const { return failed; } bool Failed() const { return failed; }
int Valid() const { return ! failed; } bool Valid() const { return ! failed; }
bool Expired() const bool Expired() const
{ {
@ -147,9 +147,6 @@ protected:
void Init(struct hostent* h); void Init(struct hostent* h);
void Clear(); void Clear();
int no_mapping; // when initializing from a file, immediately hit EOF
int init_failed;
char* req_host; char* req_host;
IPAddr req_addr; IPAddr req_addr;
uint32_t req_ttl; uint32_t req_ttl;
@ -162,9 +159,11 @@ protected:
IPAddr* addrs; IPAddr* addrs;
IntrusivePtr<ListVal> addrs_val; IntrusivePtr<ListVal> addrs_val;
int failed;
double creation_time; double creation_time;
int map_type; int map_type;
bool no_mapping; // when initializing from a file, immediately hit EOF
bool init_failed;
bool failed;
}; };
void DNS_Mgr_mapping_delete_func(void* v) void DNS_Mgr_mapping_delete_func(void* v)
@ -202,7 +201,7 @@ DNS_Mapping::DNS_Mapping(const IPAddr& addr, struct hostent* h, uint32_t ttl)
DNS_Mapping::DNS_Mapping(FILE* f) DNS_Mapping::DNS_Mapping(FILE* f)
{ {
Clear(); Clear();
init_failed = 1; init_failed = true;
req_host = 0; req_host = 0;
req_ttl = 0; req_ttl = 0;
@ -212,18 +211,21 @@ DNS_Mapping::DNS_Mapping(FILE* f)
if ( ! fgets(buf, sizeof(buf), f) ) if ( ! fgets(buf, sizeof(buf), f) )
{ {
no_mapping = 1; no_mapping = true;
return; return;
} }
char req_buf[512+1], name_buf[512+1]; char req_buf[512+1], name_buf[512+1];
int is_req_host; int is_req_host;
int failed_local;
if ( sscanf(buf, "%lf %d %512s %d %512s %d %d %" PRIu32, &creation_time, if ( sscanf(buf, "%lf %d %512s %d %512s %d %d %" PRIu32, &creation_time,
&is_req_host, req_buf, &failed, name_buf, &map_type, &num_addrs, &is_req_host, req_buf, &failed_local, name_buf, &map_type, &num_addrs,
&req_ttl) != 8 ) &req_ttl) != 8 )
return; return;
failed = static_cast<bool>(failed_local);
if ( is_req_host ) if ( is_req_host )
req_host = copy_string(req_buf); req_host = copy_string(req_buf);
else else
@ -255,7 +257,7 @@ DNS_Mapping::DNS_Mapping(FILE* f)
else else
addrs = 0; addrs = 0;
init_failed = 0; init_failed = false;
} }
DNS_Mapping::~DNS_Mapping() DNS_Mapping::~DNS_Mapping()
@ -310,8 +312,8 @@ IntrusivePtr<StringVal> DNS_Mapping::Host()
void DNS_Mapping::Init(struct hostent* h) void DNS_Mapping::Init(struct hostent* h)
{ {
no_mapping = 0; no_mapping = false;
init_failed = 0; init_failed = false;
creation_time = current_time(); creation_time = current_time();
host_val = 0; host_val = 0;
addrs_val = 0; addrs_val = 0;
@ -344,7 +346,7 @@ void DNS_Mapping::Init(struct hostent* h)
else else
addrs = 0; addrs = 0;
failed = 0; failed = false;
} }
void DNS_Mapping::Clear() void DNS_Mapping::Clear()
@ -354,9 +356,9 @@ void DNS_Mapping::Clear()
addrs = 0; addrs = 0;
host_val = 0; host_val = 0;
addrs_val = 0; addrs_val = 0;
no_mapping = 0; no_mapping = false;
map_type = 0; map_type = 0;
failed = 1; failed = true;
} }
void DNS_Mapping::Save(FILE* f) const void DNS_Mapping::Save(FILE* f) const
@ -373,7 +375,7 @@ void DNS_Mapping::Save(FILE* f) const
DNS_Mgr::DNS_Mgr(DNS_MgrMode arg_mode) DNS_Mgr::DNS_Mgr(DNS_MgrMode arg_mode)
{ {
did_init = 0; did_init = false;
mode = arg_mode; mode = arg_mode;
@ -680,15 +682,15 @@ void DNS_Mgr::Resolve()
delete requests.remove_nth(i); delete requests.remove_nth(i);
} }
int DNS_Mgr::Save() bool DNS_Mgr::Save()
{ {
if ( ! cache_name ) if ( ! cache_name )
return 0; return false;
FILE* f = fopen(cache_name, "w"); FILE* f = fopen(cache_name, "w");
if ( ! f ) if ( ! f )
return 0; return false;
Save(f, host_mappings); Save(f, host_mappings);
Save(f, addr_mappings); Save(f, addr_mappings);
@ -696,7 +698,7 @@ int DNS_Mgr::Save()
fclose(f); fclose(f);
return 1; return true;
} }
void DNS_Mgr::Event(EventHandlerPtr e, DNS_Mapping* dm) void DNS_Mgr::Event(EventHandlerPtr e, DNS_Mapping* dm)

View file

@ -57,7 +57,7 @@ public:
void Verify(); void Verify();
void Resolve(); void Resolve();
int Save(); bool Save();
const char* LookupAddrInCache(const IPAddr& addr); const char* LookupAddrInCache(const IPAddr& addr);
IntrusivePtr<TableVal> LookupNameInCache(const string& name); IntrusivePtr<TableVal> LookupNameInCache(const string& name);
@ -147,7 +147,7 @@ protected:
char* cache_name; char* cache_name;
char* dir; // directory in which cache_name resides char* dir; // directory in which cache_name resides
int did_init; bool did_init;
// DNS-related events. // DNS-related events.
EventHandlerPtr dns_mapping_valid; EventHandlerPtr dns_mapping_valid;
@ -171,7 +171,7 @@ protected:
AsyncRequest() : time(0.0), is_txt(false), processed(false) { } AsyncRequest() : time(0.0), is_txt(false), processed(false) { }
bool IsAddrReq() const { return name.length() == 0; } bool IsAddrReq() const { return name.empty(); }
void Resolved(const char* name) void Resolved(const char* name)
{ {

View file

@ -27,13 +27,13 @@ public:
: Timer(arg_t, TIMER_BREAKPOINT) : Timer(arg_t, TIMER_BREAKPOINT)
{ bp = arg_bp; } { bp = arg_bp; }
void Dispatch(double t, int is_expire); void Dispatch(double t, bool is_expire) override;
protected: protected:
DbgBreakpoint* bp; DbgBreakpoint* bp;
}; };
void BreakpointTimer::Dispatch(double t, int is_expire) void BreakpointTimer::Dispatch(double t, bool is_expire)
{ {
if ( is_expire ) if ( is_expire )
return; return;

View file

@ -237,7 +237,7 @@ static void parse_function_name(vector<ParseLocationRec>& result,
body = bodies[0].stmts.get(); body = bodies[0].stmts.get();
else else
{ {
while ( 1 ) while ( true )
{ {
debug_msg("There are multiple definitions of that event handler.\n" debug_msg("There are multiple definitions of that event handler.\n"
"Please choose one of the following options:\n"); "Please choose one of the following options:\n");

View file

@ -77,7 +77,7 @@ void choose_global_symbols_regex(const string& regex, vector<ID*>& choices,
if ( choices.size() <= 1 ) if ( choices.size() <= 1 )
return; return;
while ( 1 ) while ( true )
{ {
debug_msg("There were multiple matches, please choose:\n"); debug_msg("There were multiple matches, please choose:\n");

View file

@ -35,10 +35,10 @@ ODesc::ODesc(desc_type t, BroFile* arg_f)
} }
indent_level = 0; indent_level = 0;
is_short = 0; is_short = false;
want_quotes = 0; want_quotes = false;
do_flush = 1; do_flush = true;
include_stats = 0; include_stats = false;
indent_with_spaces = 0; indent_with_spaces = 0;
escape = false; escape = false;
utf8 = false; utf8 = false;

View file

@ -33,27 +33,27 @@ public:
~ODesc(); ~ODesc();
int IsReadable() const { return type == DESC_READABLE; } bool IsReadable() const { return type == DESC_READABLE; }
int IsPortable() const { return type == DESC_PORTABLE; } bool IsPortable() const { return type == DESC_PORTABLE; }
int IsBinary() const { return type == DESC_BINARY; } bool IsBinary() const { return type == DESC_BINARY; }
int IsShort() const { return is_short; } bool IsShort() const { return is_short; }
void SetShort() { is_short = 1; } void SetShort() { is_short = true; }
void SetShort(int s) { is_short = s; } void SetShort(bool s) { is_short = s; }
// Whether we want to have quotes around strings. // Whether we want to have quotes around strings.
int WantQuotes() const { return want_quotes; } bool WantQuotes() const { return want_quotes; }
void SetQuotes(int q) { want_quotes = q; } void SetQuotes(bool q) { want_quotes = q; }
// Whether we want to print statistics like access time and execution // Whether we want to print statistics like access time and execution
// count where available. // count where available.
int IncludeStats() const { return include_stats; } bool IncludeStats() const { return include_stats; }
void SetIncludeStats(int s) { include_stats = s; } void SetIncludeStats(bool s) { include_stats = s; }
desc_style Style() const { return style; } desc_style Style() const { return style; }
void SetStyle(desc_style s) { style = s; } void SetStyle(desc_style s) { style = s; }
void SetFlush(int arg_do_flush) { do_flush = arg_do_flush; } void SetFlush(bool arg_do_flush) { do_flush = arg_do_flush; }
void EnableEscaping(); void EnableEscaping();
void EnableUTF8(); void EnableUTF8();
@ -196,11 +196,11 @@ protected:
BroFile* f; // or the file we're using. BroFile* f; // or the file we're using.
int indent_level; int indent_level;
int is_short;
int want_quotes;
int do_flush;
int include_stats;
int indent_with_spaces; int indent_with_spaces;
bool is_short;
bool want_quotes;
bool do_flush;
bool include_stats;
std::set<const BroType*> encountered_types; std::set<const BroType*> encountered_types;
}; };

View file

@ -284,7 +284,7 @@ void* Dictionary::Lookup(const void* key, int key_size, hash_t hash) const
} }
void* Dictionary::Insert(void* key, int key_size, hash_t hash, void* val, void* Dictionary::Insert(void* key, int key_size, hash_t hash, void* val,
int copy_key) bool copy_key)
{ {
if ( ! tbl ) if ( ! tbl )
Init(DEFAULT_DICT_SIZE); Init(DEFAULT_DICT_SIZE);
@ -524,7 +524,7 @@ void Dictionary::Init2(int size)
} }
// private // private
void* Dictionary::Insert(DictEntry* new_entry, int copy_key) void* Dictionary::Insert(DictEntry* new_entry, bool copy_key)
{ {
if ( ! tbl ) if ( ! tbl )
Init(DEFAULT_DICT_SIZE); Init(DEFAULT_DICT_SIZE);
@ -623,13 +623,13 @@ int Dictionary::NextPrime(int n) const
return n; return n;
} }
int Dictionary::IsPrime(int n) const bool Dictionary::IsPrime(int n) const
{ {
for ( int j = 3; j * j <= n; ++j ) for ( int j = 3; j * j <= n; ++j )
if ( n % j == 0 ) if ( n % j == 0 )
return 0; return false;
return 1; return true;
} }
void Dictionary::StartChangeSize(int new_size) void Dictionary::StartChangeSize(int new_size)
@ -669,7 +669,7 @@ void Dictionary::MoveChains()
for ( int j = 0; j < chain->length(); ++j ) for ( int j = 0; j < chain->length(); ++j )
{ {
Insert((*chain)[j], 0); Insert((*chain)[j], false);
--num_entries; --num_entries;
--num; --num;
} }

View file

@ -42,7 +42,7 @@ public:
// that it's a heap pointer that now belongs to the Dictionary to // that it's a heap pointer that now belongs to the Dictionary to
// manage as needed. // manage as needed.
void* Insert(void* key, int key_size, hash_t hash, void* val, void* Insert(void* key, int key_size, hash_t hash, void* val,
int copy_key); bool copy_key);
// Removes the given element. Returns a pointer to the element in // Removes the given element. Returns a pointer to the element in
// case it needs to be deleted. Returns 0 if no such element exists. // case it needs to be deleted. Returns 0 if no such element exists.
@ -125,13 +125,13 @@ private:
void DeInit(); void DeInit();
// Internal version of Insert(). // Internal version of Insert().
void* Insert(DictEntry* entry, int copy_key); void* Insert(DictEntry* entry, bool copy_key);
void* DoRemove(DictEntry* entry, hash_t h, void* DoRemove(DictEntry* entry, hash_t h,
PList<DictEntry>* chain, int chain_offset); PList<DictEntry>* chain, int chain_offset);
int NextPrime(int n) const; int NextPrime(int n) const;
int IsPrime(int n) const; bool IsPrime(int n) const;
void StartChangeSize(int new_size); void StartChangeSize(int new_size);
void FinishChangeSize(); void FinishChangeSize();
void MoveChains(); void MoveChains();

View file

@ -28,14 +28,14 @@ Discarder::~Discarder()
{ {
} }
int Discarder::IsActive() bool Discarder::IsActive()
{ {
return check_ip || check_tcp || check_udp || check_icmp; return check_ip || check_tcp || check_udp || check_icmp;
} }
int Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen) bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen)
{ {
int discard_packet = 0; bool discard_packet = false;
if ( check_ip ) if ( check_ip )
{ {
@ -59,26 +59,26 @@ int Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen)
if ( proto != IPPROTO_TCP && proto != IPPROTO_UDP && if ( proto != IPPROTO_TCP && proto != IPPROTO_UDP &&
proto != IPPROTO_ICMP ) proto != IPPROTO_ICMP )
// This is not a protocol we understand. // This is not a protocol we understand.
return 0; return false;
// XXX shall we only check the first packet??? // XXX shall we only check the first packet???
if ( ip->IsFragment() ) if ( ip->IsFragment() )
// Never check any fragment. // Never check any fragment.
return 0; return false;
int ip_hdr_len = ip->HdrLen(); int ip_hdr_len = ip->HdrLen();
len -= ip_hdr_len; // remove IP header len -= ip_hdr_len; // remove IP header
caplen -= ip_hdr_len; caplen -= ip_hdr_len;
int is_tcp = (proto == IPPROTO_TCP); bool is_tcp = (proto == IPPROTO_TCP);
int is_udp = (proto == IPPROTO_UDP); bool is_udp = (proto == IPPROTO_UDP);
int min_hdr_len = is_tcp ? int min_hdr_len = is_tcp ?
sizeof(struct tcphdr) : sizeof(struct tcphdr) :
(is_udp ? sizeof(struct udphdr) : sizeof(struct icmp)); (is_udp ? sizeof(struct udphdr) : sizeof(struct icmp));
if ( len < min_hdr_len || caplen < min_hdr_len ) if ( len < min_hdr_len || caplen < min_hdr_len )
// we don't have a complete protocol header // we don't have a complete protocol header
return 0; return false;
// Where the data starts - if this is a protocol we know about, // Where the data starts - if this is a protocol we know about,
// this gets advanced past the transport header. // this gets advanced past the transport header.
@ -163,5 +163,5 @@ Val* Discarder::BuildData(const u_char* data, int hdrlen, int len, int caplen)
len = max(min(min(len, caplen), discarder_maxlen), 0); len = max(min(min(len, caplen), discarder_maxlen), 0);
return new StringVal(new BroString(data, len, 1)); return new StringVal(new BroString(data, len, true));
} }

View file

@ -4,14 +4,8 @@
#include <sys/types.h> // for u_char #include <sys/types.h> // for u_char
struct ip;
struct tcphdr;
struct udphdr;
struct icmp;
class IP_Hdr; class IP_Hdr;
class Val; class Val;
class RecordType;
class Func; class Func;
class Discarder { class Discarder {
@ -19,9 +13,9 @@ public:
Discarder(); Discarder();
~Discarder(); ~Discarder();
int IsActive(); bool IsActive();
int NextPacket(const IP_Hdr* ip, int len, int caplen); bool NextPacket(const IP_Hdr* ip, int len, int caplen);
protected: protected:
Val* BuildData(const u_char* data, int hdrlen, int len, int caplen); Val* BuildData(const u_char* data, int hdrlen, int len, int caplen);

View file

@ -20,7 +20,7 @@ public:
void ConvertCCL(CCL* ccl); void ConvertCCL(CCL* ccl);
int IsRep(int sym) const { return rep[sym] == sym; } bool IsRep(int sym) const { return rep[sym] == sym; }
int EquivRep(int sym) const { return rep[sym]; } int EquivRep(int sym) const { return rep[sym]; }
int SymEquivClass(int sym) const { return equiv_class[sym]; } int SymEquivClass(int sym) const { return equiv_class[sym]; }
int* EquivClasses() const { return equiv_class; } int* EquivClasses() const { return equiv_class; }

View file

@ -36,9 +36,7 @@ void Event::Describe(ODesc* d) const
if ( d->IsReadable() ) if ( d->IsReadable() )
d->AddSP("event"); d->AddSP("event");
int s = d->IsShort(); bool s = d->IsShort();
d->SetShort();
// handler->Describe(d);
d->SetShort(s); d->SetShort(s);
if ( ! d->IsBinary() ) if ( ! d->IsBinary() )
@ -80,7 +78,7 @@ EventMgr::EventMgr()
current_src = SOURCE_LOCAL; current_src = SOURCE_LOCAL;
current_aid = 0; current_aid = 0;
src_val = 0; src_val = 0;
draining = 0; draining = false;
} }
EventMgr::~EventMgr() EventMgr::~EventMgr()

View file

@ -117,7 +117,7 @@ public:
void Drain(); void Drain();
bool IsDraining() const { return draining; } bool IsDraining() const { return draining; }
int HasEvents() const { return head != 0; } bool HasEvents() const { return head != 0; }
// Returns the source ID of last raised event. // Returns the source ID of last raised event.
SourceID CurrentSource() const { return current_src; } SourceID CurrentSource() const { return current_src; }

View file

@ -124,7 +124,7 @@ IntrusivePtr<Val> Expr::InitVal(const BroType* t, IntrusivePtr<Val> aggr) const
if ( IsError() ) if ( IsError() )
return nullptr; return nullptr;
return check_and_promote(Eval(nullptr), t, 1); return check_and_promote(Eval(nullptr), t, true);
} }
bool Expr::IsError() const bool Expr::IsError() const
@ -439,8 +439,8 @@ IntrusivePtr<Val> BinaryExpr::Eval(Frame* f) const
if ( ! v2 ) if ( ! v2 )
return nullptr; return nullptr;
int is_vec1 = is_vector(v1.get()); bool is_vec1 = is_vector(v1.get());
int is_vec2 = is_vector(v2.get()); bool is_vec2 = is_vector(v2.get());
if ( is_vec1 && is_vec2 ) if ( is_vec1 && is_vec2 )
{ // fold pairs of elements { // fold pairs of elements
@ -2013,7 +2013,7 @@ void RefExpr::Assign(Frame* f, IntrusivePtr<Val> v)
} }
AssignExpr::AssignExpr(IntrusivePtr<Expr> arg_op1, IntrusivePtr<Expr> arg_op2, AssignExpr::AssignExpr(IntrusivePtr<Expr> arg_op1, IntrusivePtr<Expr> arg_op2,
int arg_is_init, IntrusivePtr<Val> arg_val, bool arg_is_init, IntrusivePtr<Val> arg_val,
attr_list* arg_attrs) attr_list* arg_attrs)
: BinaryExpr(EXPR_ASSIGN, arg_is_init ? : BinaryExpr(EXPR_ASSIGN, arg_is_init ?
std::move(arg_op1) : arg_op1->MakeLvalue(), std::move(arg_op1) : arg_op1->MakeLvalue(),
@ -2328,7 +2328,7 @@ void AssignExpr::EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) const
TableVal* tv = aggr->AsTableVal(); TableVal* tv = aggr->AsTableVal();
auto index = op1->Eval(f); auto index = op1->Eval(f);
auto v = check_and_promote(op2->Eval(f), t->YieldType(), 1); auto v = check_and_promote(op2->Eval(f), t->YieldType(), true);
if ( ! index || ! v ) if ( ! index || ! v )
return; return;
@ -2439,7 +2439,7 @@ bool AssignExpr::IsPure() const
} }
IndexSliceAssignExpr::IndexSliceAssignExpr(IntrusivePtr<Expr> op1, IndexSliceAssignExpr::IndexSliceAssignExpr(IntrusivePtr<Expr> op1,
IntrusivePtr<Expr> op2, int is_init) IntrusivePtr<Expr> op2, bool is_init)
: AssignExpr(std::move(op1), std::move(op2), is_init) : AssignExpr(std::move(op1), std::move(op2), is_init)
{ {
} }
@ -3285,7 +3285,7 @@ IntrusivePtr<Val> SetConstructorExpr::InitVal(const BroType* t, IntrusivePtr<Val
for ( const auto& e : exprs ) for ( const auto& e : exprs )
{ {
auto element = check_and_promote(e->Eval(nullptr), index_type, 1); auto element = check_and_promote(e->Eval(nullptr), index_type, true);
if ( ! element || ! tval->Assign(element.get(), 0) ) if ( ! element || ! tval->Assign(element.get(), 0) )
{ {
@ -3383,7 +3383,7 @@ IntrusivePtr<Val> VectorConstructorExpr::InitVal(const BroType* t, IntrusivePtr<
loop_over_list(exprs, i) loop_over_list(exprs, i)
{ {
Expr* e = exprs[i]; Expr* e = exprs[i];
auto v = check_and_promote(e->Eval(nullptr), t->YieldType(), 1); auto v = check_and_promote(e->Eval(nullptr), t->YieldType(), true);
if ( ! v || ! vec->Assign(i, std::move(v)) ) if ( ! v || ! vec->Assign(i, std::move(v)) )
{ {
@ -3855,7 +3855,7 @@ ScheduleTimer::~ScheduleTimer()
{ {
} }
void ScheduleTimer::Dispatch(double /* t */, int /* is_expire */) void ScheduleTimer::Dispatch(double /* t */, bool /* is_expire */)
{ {
if ( event ) if ( event )
mgr.Enqueue(event, std::move(args)); mgr.Enqueue(event, std::move(args));
@ -4138,15 +4138,15 @@ CallExpr::CallExpr(IntrusivePtr<Expr> arg_func,
bool CallExpr::IsPure() const bool CallExpr::IsPure() const
{ {
if ( IsError() ) if ( IsError() )
return 1; return true;
if ( ! func->IsPure() ) if ( ! func->IsPure() )
return 0; return false;
auto func_val = func->Eval(nullptr); auto func_val = func->Eval(nullptr);
if ( ! func_val ) if ( ! func_val )
return 0; return false;
::Func* f = func_val->AsFunc(); ::Func* f = func_val->AsFunc();
@ -4154,7 +4154,7 @@ bool CallExpr::IsPure() const
// functions can lead to infinite recursion if the function being // functions can lead to infinite recursion if the function being
// called here happens to be recursive (either directly // called here happens to be recursive (either directly
// or indirectly). // or indirectly).
int pure = 0; bool pure = false;
if ( f->GetKind() == Func::BUILTIN_FUNC ) if ( f->GetKind() == Func::BUILTIN_FUNC )
pure = f->IsPure() && args->IsPure(); pure = f->IsPure() && args->IsPure();
@ -4523,7 +4523,7 @@ IntrusivePtr<BroType> ListExpr::InitType() const
ti->AsTypeList(); ti->AsTypeList();
if ( ! til->IsPure() || if ( ! til->IsPure() ||
! til->AllMatch(til->PureType(), 1) ) ! til->AllMatch(til->PureType(), true) )
tl->Append({NewRef{}, til}); tl->Append({NewRef{}, til});
else else
tl->Append({NewRef{}, til->PureType()}); tl->Append({NewRef{}, til->PureType()});
@ -4547,7 +4547,7 @@ IntrusivePtr<Val> ListExpr::InitVal(const BroType* t, IntrusivePtr<Val> aggr) co
// Check whether each element of this list itself matches t, // Check whether each element of this list itself matches t,
// in which case we should expand as a ListVal. // in which case we should expand as a ListVal.
if ( ! aggr && type->AsTypeList()->AllMatch(t, 1) ) if ( ! aggr && type->AsTypeList()->AllMatch(t, true) )
{ {
auto v = make_intrusive<ListVal>(TYPE_ANY); auto v = make_intrusive<ListVal>(TYPE_ANY);
const type_list* tl = type->AsTypeList()->Types(); const type_list* tl = type->AsTypeList()->Types();
@ -4671,7 +4671,7 @@ IntrusivePtr<Val> ListExpr::InitVal(const BroType* t, IntrusivePtr<Val> aggr) co
return nullptr; return nullptr;
} }
if ( ! v->AsTableVal()->AddTo(aggr->AsTableVal(), 1) ) if ( ! v->AsTableVal()->AddTo(aggr->AsTableVal(), true) )
return nullptr; return nullptr;
} }
} }
@ -4711,16 +4711,16 @@ IntrusivePtr<Val> ListExpr::AddSetInit(const BroType* t, IntrusivePtr<Val> aggr)
return nullptr; return nullptr;
} }
if ( ! element->AsTableVal()->AddTo(tv, 1) ) if ( ! element->AsTableVal()->AddTo(tv, true) )
return nullptr; return nullptr;
continue; continue;
} }
if ( expr->Type()->Tag() == TYPE_LIST ) if ( expr->Type()->Tag() == TYPE_LIST )
element = check_and_promote(std::move(element), it, 1); element = check_and_promote(std::move(element), it, true);
else else
element = check_and_promote(std::move(element), (*it->Types())[0], 1); element = check_and_promote(std::move(element), (*it->Types())[0], true);
if ( ! element ) if ( ! element )
return nullptr; return nullptr;
@ -4781,7 +4781,7 @@ TraversalCode ListExpr::Traverse(TraversalCallback* cb) const
} }
RecordAssignExpr::RecordAssignExpr(const IntrusivePtr<Expr>& record, RecordAssignExpr::RecordAssignExpr(const IntrusivePtr<Expr>& record,
const IntrusivePtr<Expr>& init_list, int is_init) const IntrusivePtr<Expr>& init_list, bool is_init)
{ {
const expr_list& inits = init_list->AsListExpr()->Exprs(); const expr_list& inits = init_list->AsListExpr()->Exprs();
@ -4912,7 +4912,7 @@ void IsExpr::ExprDescribe(ODesc* d) const
} }
IntrusivePtr<Expr> get_assign_expr(IntrusivePtr<Expr> op1, IntrusivePtr<Expr> get_assign_expr(IntrusivePtr<Expr> op1,
IntrusivePtr<Expr> op2, int is_init) IntrusivePtr<Expr> op2, bool is_init)
{ {
if ( op1->Type()->Tag() == TYPE_RECORD && if ( op1->Type()->Tag() == TYPE_RECORD &&
op2->Type()->Tag() == TYPE_LIST ) op2->Type()->Tag() == TYPE_LIST )
@ -5005,18 +5005,18 @@ IntrusivePtr<Expr> check_and_promote_expr(Expr* const e, BroType* t)
return {NewRef{}, e}; return {NewRef{}, e};
} }
int check_and_promote_exprs(ListExpr* const elements, TypeList* types) bool check_and_promote_exprs(ListExpr* const elements, TypeList* types)
{ {
expr_list& el = elements->Exprs(); expr_list& el = elements->Exprs();
const type_list* tl = types->Types(); const type_list* tl = types->Types();
if ( tl->length() == 1 && (*tl)[0]->Tag() == TYPE_ANY ) if ( tl->length() == 1 && (*tl)[0]->Tag() == TYPE_ANY )
return 1; return true;
if ( el.length() != tl->length() ) if ( el.length() != tl->length() )
{ {
types->Error("indexing mismatch", elements); types->Error("indexing mismatch", elements);
return 0; return false;
} }
loop_over_list(el, i) loop_over_list(el, i)
@ -5027,7 +5027,7 @@ int check_and_promote_exprs(ListExpr* const elements, TypeList* types)
if ( ! promoted_e ) if ( ! promoted_e )
{ {
e->Error("type mismatch", (*tl)[i]); e->Error("type mismatch", (*tl)[i]);
return 0; return false;
} }
if ( promoted_e.get() != e ) if ( promoted_e.get() != e )
@ -5037,17 +5037,17 @@ int check_and_promote_exprs(ListExpr* const elements, TypeList* types)
} }
} }
return 1; return true;
} }
int check_and_promote_args(ListExpr* const args, RecordType* types) bool check_and_promote_args(ListExpr* const args, RecordType* types)
{ {
expr_list& el = args->Exprs(); expr_list& el = args->Exprs();
int ntypes = types->NumFields(); int ntypes = types->NumFields();
// give variadic BIFs automatic pass // give variadic BIFs automatic pass
if ( ntypes == 1 && types->FieldDecl(0)->type->Tag() == TYPE_ANY ) if ( ntypes == 1 && types->FieldDecl(0)->type->Tag() == TYPE_ANY )
return 1; return true;
if ( el.length() < ntypes ) if ( el.length() < ntypes )
{ {
@ -5063,7 +5063,7 @@ int check_and_promote_args(ListExpr* const args, RecordType* types)
if ( ! def_attr ) if ( ! def_attr )
{ {
types->Error("parameter mismatch", args); types->Error("parameter mismatch", args);
return 0; return false;
} }
def_elements.push_front(def_attr->AttrExpr()); def_elements.push_front(def_attr->AttrExpr());
@ -5084,12 +5084,12 @@ int check_and_promote_args(ListExpr* const args, RecordType* types)
return rval; return rval;
} }
int check_and_promote_exprs_to_type(ListExpr* const elements, BroType* type) bool check_and_promote_exprs_to_type(ListExpr* const elements, BroType* type)
{ {
expr_list& el = elements->Exprs(); expr_list& el = elements->Exprs();
if ( type->Tag() == TYPE_ANY ) if ( type->Tag() == TYPE_ANY )
return 1; return true;
loop_over_list(el, i) loop_over_list(el, i)
{ {
@ -5099,7 +5099,7 @@ int check_and_promote_exprs_to_type(ListExpr* const elements, BroType* type)
if ( ! promoted_e ) if ( ! promoted_e )
{ {
e->Error("type mismatch", type); e->Error("type mismatch", type);
return 0; return false;
} }
if ( promoted_e.get() != e ) if ( promoted_e.get() != e )
@ -5109,7 +5109,7 @@ int check_and_promote_exprs_to_type(ListExpr* const elements, BroType* type)
} }
} }
return 1; return true;
} }
std::optional<std::vector<IntrusivePtr<Val>>> eval_list(Frame* f, const ListExpr* l) std::optional<std::vector<IntrusivePtr<Val>>> eval_list(Frame* f, const ListExpr* l)

View file

@ -331,7 +331,7 @@ protected:
virtual IntrusivePtr<Val> AddrFold(Val* v1, Val* v2) const; virtual IntrusivePtr<Val> AddrFold(Val* v1, Val* v2) const;
virtual IntrusivePtr<Val> SubNetFold(Val* v1, Val* v2) const; virtual IntrusivePtr<Val> SubNetFold(Val* v1, Val* v2) const;
int BothConst() const { return op1->IsConst() && op2->IsConst(); } bool BothConst() const { return op1->IsConst() && op2->IsConst(); }
// Exchange op1 and op2. // Exchange op1 and op2.
void SwapOps(); void SwapOps();
@ -511,7 +511,7 @@ class AssignExpr : public BinaryExpr {
public: public:
// If val is given, evaluating this expression will always yield the val // If val is given, evaluating this expression will always yield the val
// yet still perform the assignment. Used for triggers. // yet still perform the assignment. Used for triggers.
AssignExpr(IntrusivePtr<Expr> op1, IntrusivePtr<Expr> op2, int is_init, AssignExpr(IntrusivePtr<Expr> op1, IntrusivePtr<Expr> op2, bool is_init,
IntrusivePtr<Val> val = nullptr, attr_list* attrs = nullptr); IntrusivePtr<Val> val = nullptr, attr_list* attrs = nullptr);
IntrusivePtr<Val> Eval(Frame* f) const override; IntrusivePtr<Val> Eval(Frame* f) const override;
@ -525,14 +525,14 @@ protected:
bool TypeCheck(attr_list* attrs = 0); bool TypeCheck(attr_list* attrs = 0);
bool TypeCheckArithmetics(TypeTag bt1, TypeTag bt2); bool TypeCheckArithmetics(TypeTag bt1, TypeTag bt2);
int is_init; bool is_init;
IntrusivePtr<Val> val; // optional IntrusivePtr<Val> val; // optional
}; };
class IndexSliceAssignExpr : public AssignExpr { class IndexSliceAssignExpr : public AssignExpr {
public: public:
IndexSliceAssignExpr(IntrusivePtr<Expr> op1, IndexSliceAssignExpr(IntrusivePtr<Expr> op1,
IntrusivePtr<Expr> op2, int is_init); IntrusivePtr<Expr> op2, bool is_init);
IntrusivePtr<Val> Eval(Frame* f) const override; IntrusivePtr<Val> Eval(Frame* f) const override;
}; };
@ -744,7 +744,7 @@ public:
ScheduleTimer(const EventHandlerPtr& event, zeek::Args args, double t); ScheduleTimer(const EventHandlerPtr& event, zeek::Args args, double t);
~ScheduleTimer() override; ~ScheduleTimer() override;
void Dispatch(double t, int is_expire) override; void Dispatch(double t, bool is_expire) override;
protected: protected:
EventHandlerPtr event; EventHandlerPtr event;
@ -879,7 +879,7 @@ protected:
class RecordAssignExpr : public ListExpr { class RecordAssignExpr : public ListExpr {
public: public:
RecordAssignExpr(const IntrusivePtr<Expr>& record, const IntrusivePtr<Expr>& init_list, int is_init); RecordAssignExpr(const IntrusivePtr<Expr>& record, const IntrusivePtr<Expr>& init_list, bool is_init);
}; };
class CastExpr : public UnaryExpr { class CastExpr : public UnaryExpr {
@ -912,7 +912,7 @@ inline Val* Expr::ExprVal() const
// Decides whether to return an AssignExpr or a RecordAssignExpr. // Decides whether to return an AssignExpr or a RecordAssignExpr.
IntrusivePtr<Expr> get_assign_expr(IntrusivePtr<Expr> op1, IntrusivePtr<Expr> get_assign_expr(IntrusivePtr<Expr> op1,
IntrusivePtr<Expr> op2, int is_init); IntrusivePtr<Expr> op2, bool is_init);
// Type-check the given expression(s) against the given type(s). Complain // Type-check the given expression(s) against the given type(s). Complain
// if the expression cannot match the given type, returning 0. If it can // if the expression cannot match the given type, returning 0. If it can
@ -931,9 +931,9 @@ IntrusivePtr<Expr> get_assign_expr(IntrusivePtr<Expr> op1,
*/ */
extern IntrusivePtr<Expr> check_and_promote_expr(Expr* e, BroType* t); extern IntrusivePtr<Expr> check_and_promote_expr(Expr* e, BroType* t);
extern int check_and_promote_exprs(ListExpr* elements, TypeList* types); extern bool check_and_promote_exprs(ListExpr* elements, TypeList* types);
extern int check_and_promote_args(ListExpr* args, RecordType* types); extern bool check_and_promote_args(ListExpr* args, RecordType* types);
extern int check_and_promote_exprs_to_type(ListExpr* elements, BroType* type); extern bool check_and_promote_exprs_to_type(ListExpr* elements, BroType* type);
// Returns a ListExpr simplified down to a list a values, or nil // Returns a ListExpr simplified down to a list a values, or nil
// if they couldn't all be reduced. // if they couldn't all be reduced.

View file

@ -87,12 +87,12 @@ BroFile::BroFile(const char* arg_name, const char* arg_access)
f = stderr; f = stderr;
if ( f ) if ( f )
is_open = 1; is_open = true;
else if ( ! Open() ) else if ( ! Open() )
{ {
reporter->Error("cannot open %s: %s", name, strerror(errno)); reporter->Error("cannot open %s: %s", name, strerror(errno));
is_open = 0; is_open = false;
} }
} }
@ -139,11 +139,11 @@ bool BroFile::Open(FILE* file, const char* mode)
if ( ! f ) if ( ! f )
{ {
is_open = 0; is_open = false;
return false; return false;
} }
is_open = 1; is_open = true;
open_files.emplace_back(std::make_pair(name, this)); open_files.emplace_back(std::make_pair(name, this));
RaiseOpenEvent(); RaiseOpenEvent();
@ -166,7 +166,8 @@ BroFile::~BroFile()
void BroFile::Init() void BroFile::Init()
{ {
open_time = is_open = 0; open_time = 0;
is_open = false;
attrs = 0; attrs = 0;
buffered = true; buffered = true;
raw_output = false; raw_output = false;
@ -203,25 +204,26 @@ void BroFile::SetBuf(bool arg_buffered)
buffered = arg_buffered; buffered = arg_buffered;
} }
int BroFile::Close() bool BroFile::Close()
{ {
if ( ! is_open ) if ( ! is_open )
return 1; return true;
// Do not close stdin/stdout/stderr. // Do not close stdin/stdout/stderr.
if ( f == stdin || f == stdout || f == stderr ) if ( f == stdin || f == stdout || f == stderr )
return 0; return false;
if ( ! f ) if ( ! f )
return 0; return false;
fclose(f); fclose(f);
f = nullptr; f = nullptr;
open_time = is_open = 0; open_time = 0;
is_open = false;
Unlink(); Unlink();
return 1; return true;
} }
void BroFile::Unlink() void BroFile::Unlink()
@ -305,10 +307,10 @@ void BroFile::CloseOpenFiles()
} }
} }
int BroFile::Write(const char* data, int len) bool BroFile::Write(const char* data, int len)
{ {
if ( ! is_open ) if ( ! is_open )
return 0; return false;
if ( ! len ) if ( ! len )
len = strlen(data); len = strlen(data);
@ -355,4 +357,3 @@ BroFile* BroFile::GetFile(const char* name)
return new BroFile(name, "w"); return new BroFile(name, "w");
} }

View file

@ -29,7 +29,7 @@ public:
const char* Name() const; const char* Name() const;
// Returns false if an error occured. // Returns false if an error occured.
int Write(const char* data, int len = 0); bool Write(const char* data, int len = 0);
void Flush() { fflush(f); } void Flush() { fflush(f); }
@ -42,11 +42,11 @@ public:
// Whether the file is open in a general sense; it might // Whether the file is open in a general sense; it might
// not be open as a Unix file due to our management of // not be open as a Unix file due to our management of
// a finite number of FDs. // a finite number of FDs.
int IsOpen() const { return is_open; } bool IsOpen() const { return is_open; }
// Returns true if the close made sense, false if it was already // Returns true if the close made sense, false if it was already
// closed, not active, or whatever. // closed, not active, or whatever.
int Close(); bool Close();
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
@ -97,10 +97,10 @@ protected:
IntrusivePtr<BroType> t; IntrusivePtr<BroType> t;
char* name; char* name;
char* access; char* access;
int is_open; // whether the file is open in a general sense
Attributes* attrs; Attributes* attrs;
bool buffered;
double open_time; double open_time;
bool is_open; // whether the file is open in a general sense
bool buffered;
bool raw_output; bool raw_output;
static const int MIN_BUFFER_SIZE = 1024; static const int MIN_BUFFER_SIZE = 1024;

View file

@ -18,7 +18,7 @@ FragTimer::~FragTimer()
f->ClearTimer(); f->ClearTimer();
} }
void FragTimer::Dispatch(double t, int /* is_expire */) void FragTimer::Dispatch(double t, bool /* is_expire */)
{ {
if ( f ) if ( f )
f->Expire(t); f->Expire(t);

View file

@ -60,7 +60,7 @@ public:
{ f = arg_f; } { f = arg_f; }
~FragTimer() override; ~FragTimer() override;
void Dispatch(double t, int is_expire) override; void Dispatch(double t, bool is_expire) override;
// Break the association between this timer and its creator. // Break the association between this timer and its creator.
void ClearReassembler() { f = 0; } void ClearReassembler() { f = 0; }

View file

@ -289,7 +289,7 @@ BroFunc::~BroFunc()
Unref(closure); Unref(closure);
} }
int BroFunc::IsPure() const bool BroFunc::IsPure() const
{ {
return std::all_of(bodies.begin(), bodies.end(), return std::all_of(bodies.begin(), bodies.end(),
[](const Body& b) { return b.stmts->IsPure(); }); [](const Body& b) { return b.stmts->IsPure(); });
@ -575,7 +575,7 @@ IntrusivePtr<Stmt> BroFunc::AddInits(IntrusivePtr<Stmt> body, id_list* inits)
} }
BuiltinFunc::BuiltinFunc(built_in_func arg_func, const char* arg_name, BuiltinFunc::BuiltinFunc(built_in_func arg_func, const char* arg_name,
int arg_is_pure) bool arg_is_pure)
: Func(BUILTIN_FUNC) : Func(BUILTIN_FUNC)
{ {
func = arg_func; func = arg_func;
@ -596,7 +596,7 @@ BuiltinFunc::~BuiltinFunc()
{ {
} }
int BuiltinFunc::IsPure() const bool BuiltinFunc::IsPure() const
{ {
return is_pure; return is_pure;
} }

View file

@ -39,7 +39,7 @@ public:
~Func() override; ~Func() override;
virtual int IsPure() const = 0; virtual bool IsPure() const = 0;
function_flavor Flavor() const { return FType()->Flavor(); } function_flavor Flavor() const { return FType()->Flavor(); }
struct Body { struct Body {
@ -123,7 +123,7 @@ public:
BroFunc(ID* id, IntrusivePtr<Stmt> body, id_list* inits, size_t frame_size, int priority); BroFunc(ID* id, IntrusivePtr<Stmt> body, id_list* inits, size_t frame_size, int priority);
~BroFunc() override; ~BroFunc() override;
int IsPure() const override; bool IsPure() const override;
IntrusivePtr<Val> Call(const zeek::Args& args, Frame* parent) const override; IntrusivePtr<Val> Call(const zeek::Args& args, Frame* parent) const override;
/** /**
@ -195,10 +195,10 @@ using built_in_func = Val* (*)(Frame* frame, const zeek::Args* args);
class BuiltinFunc : public Func { class BuiltinFunc : public Func {
public: public:
BuiltinFunc(built_in_func func, const char* name, int is_pure); BuiltinFunc(built_in_func func, const char* name, bool is_pure);
~BuiltinFunc() override; ~BuiltinFunc() override;
int IsPure() const override; bool IsPure() const override;
IntrusivePtr<Val> Call(const zeek::Args& args, Frame* parent) const override; IntrusivePtr<Val> Call(const zeek::Args& args, Frame* parent) const override;
built_in_func TheFunc() const { return func; } built_in_func TheFunc() const { return func; }
@ -208,7 +208,7 @@ protected:
BuiltinFunc() { func = 0; is_pure = 0; } BuiltinFunc() { func = 0; is_pure = 0; }
built_in_func func; built_in_func func;
int is_pure; bool is_pure;
}; };

View file

@ -36,7 +36,6 @@ HashKey::HashKey(bro_int_t i)
key = (void*) &key_u; key = (void*) &key_u;
size = sizeof(i); size = sizeof(i);
hash = HashBytes(key, size); hash = HashBytes(key, size);
is_our_dynamic = 0;
} }
HashKey::HashKey(bro_uint_t u) HashKey::HashKey(bro_uint_t u)
@ -45,7 +44,6 @@ HashKey::HashKey(bro_uint_t u)
key = (void*) &key_u; key = (void*) &key_u;
size = sizeof(u); size = sizeof(u);
hash = HashBytes(key, size); hash = HashBytes(key, size);
is_our_dynamic = 0;
} }
HashKey::HashKey(uint32_t u) HashKey::HashKey(uint32_t u)
@ -54,7 +52,6 @@ HashKey::HashKey(uint32_t u)
key = (void*) &key_u; key = (void*) &key_u;
size = sizeof(u); size = sizeof(u);
hash = HashBytes(key, size); hash = HashBytes(key, size);
is_our_dynamic = 0;
} }
HashKey::HashKey(const uint32_t u[], int n) HashKey::HashKey(const uint32_t u[], int n)
@ -62,7 +59,6 @@ HashKey::HashKey(const uint32_t u[], int n)
size = n * sizeof(u[0]); size = n * sizeof(u[0]);
key = (void*) u; key = (void*) u;
hash = HashBytes(key, size); hash = HashBytes(key, size);
is_our_dynamic = 0;
} }
HashKey::HashKey(double d) HashKey::HashKey(double d)
@ -76,7 +72,6 @@ HashKey::HashKey(double d)
key = (void*) &key_u; key = (void*) &key_u;
size = sizeof(d); size = sizeof(d);
hash = HashBytes(key, size); hash = HashBytes(key, size);
is_our_dynamic = 0;
} }
HashKey::HashKey(const void* p) HashKey::HashKey(const void* p)
@ -85,7 +80,6 @@ HashKey::HashKey(const void* p)
key = (void*) &key_u; key = (void*) &key_u;
size = sizeof(p); size = sizeof(p);
hash = HashBytes(key, size); hash = HashBytes(key, size);
is_our_dynamic = 0;
} }
HashKey::HashKey(const char* s) HashKey::HashKey(const char* s)
@ -93,7 +87,6 @@ HashKey::HashKey(const char* s)
size = strlen(s); // note - skip final \0 size = strlen(s); // note - skip final \0
key = (void*) s; key = (void*) s;
hash = HashBytes(key, size); hash = HashBytes(key, size);
is_our_dynamic = 0;
} }
HashKey::HashKey(const BroString* s) HashKey::HashKey(const BroString* s)
@ -101,13 +94,12 @@ HashKey::HashKey(const BroString* s)
size = s->Len(); size = s->Len();
key = (void*) s->Bytes(); key = (void*) s->Bytes();
hash = HashBytes(key, size); hash = HashBytes(key, size);
is_our_dynamic = 0;
} }
HashKey::HashKey(int copy_key, void* arg_key, int arg_size) HashKey::HashKey(int copy_key, void* arg_key, int arg_size)
{ {
size = arg_size; size = arg_size;
is_our_dynamic = 1; is_our_dynamic = true;
if ( copy_key ) if ( copy_key )
{ {
@ -125,7 +117,7 @@ HashKey::HashKey(const void* arg_key, int arg_size, hash_t arg_hash)
size = arg_size; size = arg_size;
hash = arg_hash; hash = arg_hash;
key = CopyKey(arg_key, size); key = CopyKey(arg_key, size);
is_our_dynamic = 1; is_our_dynamic = true;
} }
HashKey::HashKey(const void* arg_key, int arg_size, hash_t arg_hash, HashKey::HashKey(const void* arg_key, int arg_size, hash_t arg_hash,
@ -134,7 +126,6 @@ HashKey::HashKey(const void* arg_key, int arg_size, hash_t arg_hash,
size = arg_size; size = arg_size;
hash = arg_hash; hash = arg_hash;
key = const_cast<void*>(arg_key); key = const_cast<void*>(arg_key);
is_our_dynamic = 0;
} }
HashKey::HashKey(const void* bytes, int arg_size) HashKey::HashKey(const void* bytes, int arg_size)
@ -142,14 +133,14 @@ HashKey::HashKey(const void* bytes, int arg_size)
size = arg_size; size = arg_size;
key = CopyKey(bytes, size); key = CopyKey(bytes, size);
hash = HashBytes(key, size); hash = HashBytes(key, size);
is_our_dynamic = 1; is_our_dynamic = true;
} }
void* HashKey::TakeKey() void* HashKey::TakeKey()
{ {
if ( is_our_dynamic ) if ( is_our_dynamic )
{ {
is_our_dynamic = 0; is_our_dynamic = false;
return key; return key;
} }
else else

View file

@ -81,9 +81,9 @@ protected:
} key_u; } key_u;
void* key; void* key;
int is_our_dynamic;
int size;
hash_t hash; hash_t hash;
int size;
bool is_our_dynamic = false;
}; };
extern void init_hash_function(); extern void init_hash_function();

View file

@ -125,7 +125,7 @@ void ID::SetVal(IntrusivePtr<Val> v, init_class c)
return; return;
} }
else else
v->AddTo(val, 0); v->AddTo(val, false);
} }
else else
{ {
@ -313,7 +313,7 @@ TraversalCode ID::Traverse(TraversalCallback* cb) const
void ID::Error(const char* msg, const BroObj* o2) void ID::Error(const char* msg, const BroObj* o2)
{ {
BroObj::Error(msg, o2, 1); BroObj::Error(msg, o2, true);
SetType(error_type()); SetType(error_type());
} }

View file

@ -66,7 +66,7 @@ static VectorVal* BuildOptionsVal(const u_char* data, int len)
uint16_t off = 2 * sizeof(uint8_t); uint16_t off = 2 * sizeof(uint8_t);
rv->Assign(1, val_mgr->GetCount(opt->ip6o_len)); rv->Assign(1, val_mgr->GetCount(opt->ip6o_len));
rv->Assign(2, make_intrusive<StringVal>( rv->Assign(2, make_intrusive<StringVal>(
new BroString(data + off, opt->ip6o_len, 1))); new BroString(data + off, opt->ip6o_len, true)));
data += opt->ip6o_len + off; data += opt->ip6o_len + off;
len -= opt->ip6o_len + off; len -= opt->ip6o_len + off;
} }
@ -132,7 +132,7 @@ RecordVal* IPv6_Hdr::BuildRecordVal(VectorVal* chain) const
rv->Assign(2, val_mgr->GetCount(rt->ip6r_type)); rv->Assign(2, val_mgr->GetCount(rt->ip6r_type));
rv->Assign(3, val_mgr->GetCount(rt->ip6r_segleft)); rv->Assign(3, val_mgr->GetCount(rt->ip6r_segleft));
uint16_t off = 4 * sizeof(uint8_t); uint16_t off = 4 * sizeof(uint8_t);
rv->Assign(4, make_intrusive<StringVal>(new BroString(data + off, Length() - off, 1))); rv->Assign(4, make_intrusive<StringVal>(new BroString(data + off, Length() - off, true)));
} }
break; break;
@ -163,7 +163,7 @@ RecordVal* IPv6_Hdr::BuildRecordVal(VectorVal* chain) const
// Payload Len was non-zero for this header. // Payload Len was non-zero for this header.
rv->Assign(4, val_mgr->GetCount(ntohl(((uint32_t*)data)[2]))); rv->Assign(4, val_mgr->GetCount(ntohl(((uint32_t*)data)[2])));
uint16_t off = 3 * sizeof(uint32_t); uint16_t off = 3 * sizeof(uint32_t);
rv->Assign(5, make_intrusive<StringVal>(new BroString(data + off, Length() - off, 1))); rv->Assign(5, make_intrusive<StringVal>(new BroString(data + off, Length() - off, true)));
} }
} }
break; break;

View file

@ -136,6 +136,7 @@ public:
} }
bool empty() const noexcept { return num_entries == 0; } bool empty() const noexcept { return num_entries == 0; }
size_t size() const noexcept { return num_entries; }
int length() const { return num_entries; } int length() const { return num_entries; }
int max() const { return max_entries; } int max() const { return max_entries; }

View file

@ -58,7 +58,7 @@ BroObj::~BroObj()
delete location; delete location;
} }
void BroObj::Warn(const char* msg, const BroObj* obj2, int pinpoint_only, const Location* expr_location) const void BroObj::Warn(const char* msg, const BroObj* obj2, bool pinpoint_only, const Location* expr_location) const
{ {
ODesc d; ODesc d;
DoMsg(&d, msg, obj2, pinpoint_only, expr_location); DoMsg(&d, msg, obj2, pinpoint_only, expr_location);
@ -66,7 +66,7 @@ void BroObj::Warn(const char* msg, const BroObj* obj2, int pinpoint_only, const
reporter->PopLocation(); reporter->PopLocation();
} }
void BroObj::Error(const char* msg, const BroObj* obj2, int pinpoint_only, const Location* expr_location) const void BroObj::Error(const char* msg, const BroObj* obj2, bool pinpoint_only, const Location* expr_location) const
{ {
if ( suppress_errors ) if ( suppress_errors )
return; return;
@ -158,7 +158,7 @@ void BroObj::UpdateLocationEndInfo(const Location& end)
} }
void BroObj::DoMsg(ODesc* d, const char s1[], const BroObj* obj2, void BroObj::DoMsg(ODesc* d, const char s1[], const BroObj* obj2,
int pinpoint_only, const Location* expr_location) const bool pinpoint_only, const Location* expr_location) const
{ {
d->SetShort(); d->SetShort();
@ -175,7 +175,7 @@ void BroObj::DoMsg(ODesc* d, const char s1[], const BroObj* obj2,
reporter->PushLocation(GetLocationInfo(), loc2); reporter->PushLocation(GetLocationInfo(), loc2);
} }
void BroObj::PinPoint(ODesc* d, const BroObj* obj2, int pinpoint_only) const void BroObj::PinPoint(ODesc* d, const BroObj* obj2, bool pinpoint_only) const
{ {
d->Add(" ("); d->Add(" (");
Describe(d); Describe(d);

View file

@ -81,9 +81,9 @@ public:
// included in the message, though if pinpoint_only is non-zero, // included in the message, though if pinpoint_only is non-zero,
// then obj2 is only used to pinpoint the location. // then obj2 is only used to pinpoint the location.
void Warn(const char* msg, const BroObj* obj2 = 0, void Warn(const char* msg, const BroObj* obj2 = 0,
int pinpoint_only = 0, const Location* expr_location = 0) const; bool pinpoint_only = false, const Location* expr_location = 0) const;
void Error(const char* msg, const BroObj* obj2 = 0, void Error(const char* msg, const BroObj* obj2 = 0,
int pinpoint_only = 0, const Location* expr_location = 0) const; bool pinpoint_only = false, const Location* expr_location = 0) const;
// Report internal errors. // Report internal errors.
void BadTag(const char* msg, const char* t1 = 0, void BadTag(const char* msg, const char* t1 = 0,
@ -135,9 +135,9 @@ private:
friend class SuppressErrors; friend class SuppressErrors;
void DoMsg(ODesc* d, const char s1[], const BroObj* obj2 = 0, void DoMsg(ODesc* d, const char s1[], const BroObj* obj2 = 0,
int pinpoint_only = 0, const Location* expr_location = 0) const; bool pinpoint_only = false, const Location* expr_location = 0) const;
void PinPoint(ODesc* d, const BroObj* obj2 = 0, void PinPoint(ODesc* d, const BroObj* obj2 = 0,
int pinpoint_only = 0) const; bool pinpoint_only = false) const;
friend inline void Ref(BroObj* o); friend inline void Ref(BroObj* o);
friend inline void Unref(BroObj* o); friend inline void Unref(BroObj* o);

View file

@ -754,14 +754,14 @@ BroType* BloomFilterVal::Type() const
void BloomFilterVal::Add(const Val* val) void BloomFilterVal::Add(const Val* val)
{ {
HashKey* key = hash->ComputeHash(val, 1); HashKey* key = hash->ComputeHash(val, true);
bloom_filter->Add(key); bloom_filter->Add(key);
delete key; delete key;
} }
size_t BloomFilterVal::Count(const Val* val) const size_t BloomFilterVal::Count(const Val* val) const
{ {
HashKey* key = hash->ComputeHash(val, 1); HashKey* key = hash->ComputeHash(val, true);
size_t cnt = bloom_filter->Count(key); size_t cnt = bloom_filter->Count(key);
delete key; delete key;
return cnt; return cnt;
@ -924,7 +924,7 @@ BroType* CardinalityVal::Type() const
void CardinalityVal::Add(const Val* val) void CardinalityVal::Add(const Val* val)
{ {
HashKey* key = hash->ComputeHash(val, 1); HashKey* key = hash->ComputeHash(val, true);
c->AddElement(key->Hash()); c->AddElement(key->Hash());
delete key; delete key;
} }

View file

@ -16,7 +16,7 @@ prefix_t* PrefixTable::MakePrefix(const IPAddr& addr, int width)
IPPrefix PrefixTable::PrefixToIPPrefix(prefix_t* prefix) IPPrefix PrefixTable::PrefixToIPPrefix(prefix_t* prefix)
{ {
return IPPrefix(IPAddr(IPv6, reinterpret_cast<const uint32_t*>(&prefix->add.sin6), IPAddr::Network), prefix->bitlen, 1); return IPPrefix(IPAddr(IPv6, reinterpret_cast<const uint32_t*>(&prefix->add.sin6), IPAddr::Network), prefix->bitlen, true);
} }
void* PrefixTable::Insert(const IPAddr& addr, int width, void* data) void* PrefixTable::Insert(const IPAddr& addr, int width, void* data)
@ -173,7 +173,7 @@ PrefixTable::iterator PrefixTable::InitIterator()
void* PrefixTable::GetNext(iterator* i) void* PrefixTable::GetNext(iterator* i)
{ {
while ( 1 ) while ( true )
{ {
i->Xnode = i->Xrn; i->Xnode = i->Xrn;
if ( ! i->Xnode ) if ( ! i->Xnode )

View file

@ -116,10 +116,10 @@ void Specific_RE_Matcher::MakeCaseInsensitive()
pattern_text = s; pattern_text = s;
} }
int Specific_RE_Matcher::Compile(int lazy) bool Specific_RE_Matcher::Compile(bool lazy)
{ {
if ( ! pattern_text ) if ( ! pattern_text )
return 0; return false;
rem = this; rem = this;
RE_set_input(pattern_text); RE_set_input(pattern_text);
@ -132,7 +132,7 @@ int Specific_RE_Matcher::Compile(int lazy)
reporter->Error("error compiling pattern /%s/", pattern_text); reporter->Error("error compiling pattern /%s/", pattern_text);
Unref(nfa); Unref(nfa);
nfa = 0; nfa = 0;
return 0; return false;
} }
EC()->BuildECs(); EC()->BuildECs();
@ -145,10 +145,10 @@ int Specific_RE_Matcher::Compile(int lazy)
ecs = EC()->EquivClasses(); ecs = EC()->EquivClasses();
return 1; return true;
} }
int Specific_RE_Matcher::CompileSet(const string_list& set, const int_list& idx) bool Specific_RE_Matcher::CompileSet(const string_list& set, const int_list& idx)
{ {
if ( (size_t)set.length() != idx.size() ) if ( (size_t)set.length() != idx.size() )
reporter->InternalError("compileset: lengths of sets differ"); reporter->InternalError("compileset: lengths of sets differ");
@ -173,7 +173,7 @@ int Specific_RE_Matcher::CompileSet(const string_list& set, const int_list& idx)
Unref(nfa); Unref(nfa);
nfa = 0; nfa = 0;
return 0; return false;
} }
nfa->FinalState()->SetAccept(idx[i]); nfa->FinalState()->SetAccept(idx[i]);
@ -192,7 +192,7 @@ int Specific_RE_Matcher::CompileSet(const string_list& set, const int_list& idx)
dfa = new DFA_Machine(nfa, EC()); dfa = new DFA_Machine(nfa, EC());
ecs = EC()->EquivClasses(); ecs = EC()->EquivClasses();
return 1; return true;
} }
string Specific_RE_Matcher::LookupDef(const string& def) string Specific_RE_Matcher::LookupDef(const string& def)
@ -204,12 +204,12 @@ string Specific_RE_Matcher::LookupDef(const string& def)
return string(); return string();
} }
int Specific_RE_Matcher::MatchAll(const char* s) bool Specific_RE_Matcher::MatchAll(const char* s)
{ {
return MatchAll((const u_char*)(s), strlen(s)); return MatchAll((const u_char*)(s), strlen(s));
} }
int Specific_RE_Matcher::MatchAll(const BroString* s) bool Specific_RE_Matcher::MatchAll(const BroString* s)
{ {
// s->Len() does not include '\0'. // s->Len() does not include '\0'.
return MatchAll(s->Bytes(), s->Len()); return MatchAll(s->Bytes(), s->Len());
@ -235,7 +235,7 @@ int Specific_RE_Matcher::LongestMatch(const BroString* s)
return LongestMatch(s->Bytes(), s->Len()); return LongestMatch(s->Bytes(), s->Len());
} }
int Specific_RE_Matcher::MatchAll(const u_char* bv, int n) bool Specific_RE_Matcher::MatchAll(const u_char* bv, int n)
{ {
if ( ! dfa ) if ( ! dfa )
// An empty pattern matches "all" iff what's being // An empty pattern matches "all" iff what's being
@ -480,7 +480,7 @@ void RE_Matcher::MakeCaseInsensitive()
re_exact->MakeCaseInsensitive(); re_exact->MakeCaseInsensitive();
} }
int RE_Matcher::Compile(int lazy) bool RE_Matcher::Compile(bool lazy)
{ {
return re_anywhere->Compile(lazy) && re_exact->Compile(lazy); return re_anywhere->Compile(lazy) && re_exact->Compile(lazy);
} }

View file

@ -54,7 +54,7 @@ public:
void SetPat(const char* pat) { pattern_text = copy_string(pat); } void SetPat(const char* pat) { pattern_text = copy_string(pat); }
int Compile(int lazy = 0); bool Compile(bool lazy = false);
// The following is vestigial from flex's use of "{name}" definitions. // The following is vestigial from flex's use of "{name}" definitions.
// It's here because at some point we may want to support such // It's here because at some point we may want to support such
@ -80,14 +80,14 @@ public:
void ConvertCCLs(); void ConvertCCLs();
int MatchAll(const char* s); bool MatchAll(const char* s);
int MatchAll(const BroString* s); bool MatchAll(const BroString* s);
// Compiles a set of regular expressions simultaniously. // Compiles a set of regular expressions simultaniously.
// 'idx' contains indizes associated with the expressions. // 'idx' contains indizes associated with the expressions.
// On matching, the set of indizes is returned which correspond // On matching, the set of indizes is returned which correspond
// to the matching expressions. (idx must not contain zeros). // to the matching expressions. (idx must not contain zeros).
int CompileSet(const string_list& set, const int_list& idx); bool CompileSet(const string_list& set, const int_list& idx);
// Returns the position in s just beyond where the first match // Returns the position in s just beyond where the first match
// occurs, or 0 if there is no such position in s. Note that // occurs, or 0 if there is no such position in s. Note that
@ -119,7 +119,7 @@ protected:
// appending to an existing pattern_text. // appending to an existing pattern_text.
void AddPat(const char* pat, const char* orig_fmt, const char* app_fmt); void AddPat(const char* pat, const char* orig_fmt, const char* app_fmt);
int MatchAll(const u_char* bv, int n); bool MatchAll(const u_char* bv, int n);
int Match(const u_char* bv, int n); int Match(const u_char* bv, int n);
match_type mt; match_type mt;
@ -186,12 +186,12 @@ public:
// Makes the matcher as specified to date case-insensitive. // Makes the matcher as specified to date case-insensitive.
void MakeCaseInsensitive(); void MakeCaseInsensitive();
int Compile(int lazy = 0); bool Compile(bool lazy = false);
// Returns true if s exactly matches the pattern, false otherwise. // Returns true if s exactly matches the pattern, false otherwise.
int MatchExactly(const char* s) bool MatchExactly(const char* s)
{ return re_exact->MatchAll(s); } { return re_exact->MatchAll(s); }
int MatchExactly(const BroString* s) bool MatchExactly(const BroString* s)
{ return re_exact->MatchAll(s); } { return re_exact->MatchAll(s); }
// Returns the position in s just beyond where the first match // Returns the position in s just beyond where the first match

View file

@ -265,7 +265,7 @@ public:
void ClearBlocks(); void ClearBlocks();
void ClearOldBlocks(); void ClearOldBlocks();
int HasBlocks() const bool HasBlocks() const
{ return ! block_list.Empty(); } { return ! block_list.Empty(); }
uint64_t LastReassemSeq() const { return last_reassem_seq; } uint64_t LastReassemSeq() const { return last_reassem_seq; }

View file

@ -244,7 +244,7 @@ public:
: Timer(t + timeout, TIMER_NET_WEIRD_EXPIRE), weird_name(name) : Timer(t + timeout, TIMER_NET_WEIRD_EXPIRE), weird_name(name)
{} {}
void Dispatch(double t, int is_expire) override void Dispatch(double t, bool is_expire) override
{ reporter->ResetNetWeird(weird_name); } { reporter->ResetNetWeird(weird_name); }
std::string weird_name; std::string weird_name;
@ -258,7 +258,7 @@ public:
: Timer(t + timeout, TIMER_FLOW_WEIRD_EXPIRE), endpoints(std::move(p)) : Timer(t + timeout, TIMER_FLOW_WEIRD_EXPIRE), endpoints(std::move(p))
{} {}
void Dispatch(double t, int is_expire) override void Dispatch(double t, bool is_expire) override
{ reporter->ResetFlowWeird(endpoints.first, endpoints.second); } { reporter->ResetFlowWeird(endpoints.first, endpoints.second); }
IPPair endpoints; IPPair endpoints;

View file

@ -195,4 +195,3 @@ void RuleConditionEval::PrintDebug()
{ {
fprintf(stderr, " RuleConditionEval: %s\n", id->Name()); fprintf(stderr, " RuleConditionEval: %s\n", id->Name());
} }

View file

@ -758,8 +758,8 @@ RuleEndpointState* RuleMatcher::InitEndpoint(analyzer::Analyzer* analyzer,
// Evaluate all rules on this node which don't contain // Evaluate all rules on this node which don't contain
// any patterns. // any patterns.
for ( Rule* r = hdr_test->pure_rules; r; r = r->next ) for ( Rule* r = hdr_test->pure_rules; r; r = r->next )
if ( EvalRuleConditions(r, state, 0, 0, 0) ) if ( EvalRuleConditions(r, state, 0, 0, false) )
ExecRuleActions(r, state, 0, 0, 0); ExecRuleActions(r, state, 0, 0, false);
// If we're on or above the RE_level, we may have some // If we're on or above the RE_level, we may have some
// pattern matching to do. // pattern matching to do.
@ -953,17 +953,17 @@ void RuleMatcher::Match(RuleEndpointState* state, Rule::PatternType type,
if ( ! state->matched_by_patterns.is_member(r) ) if ( ! state->matched_by_patterns.is_member(r) )
{ {
state->matched_by_patterns.push_back(r); state->matched_by_patterns.push_back(r);
BroString* s = new BroString(data, data_len, 0); BroString* s = new BroString(data, data_len, false);
state->matched_text.push_back(s); state->matched_text.push_back(s);
} }
DBG_LOG(DBG_RULES, "And has not already fired"); DBG_LOG(DBG_RULES, "And has not already fired");
// Eval additional conditions. // Eval additional conditions.
if ( ! EvalRuleConditions(r, state, data, data_len, 0) ) if ( ! EvalRuleConditions(r, state, data, data_len, false) )
continue; continue;
// Found a match. // Found a match.
ExecRuleActions(r, state, data, data_len, 0); ExecRuleActions(r, state, data, data_len, false);
} }
} }
} }
@ -977,11 +977,11 @@ void RuleMatcher::FinishEndpoint(RuleEndpointState* state)
// although they have not matched at the beginning. So, we have // although they have not matched at the beginning. So, we have
// to test the candidates here. // to test the candidates here.
ExecPureRules(state, 1); ExecPureRules(state, true);
loop_over_list(state->matched_by_patterns, i) loop_over_list(state->matched_by_patterns, i)
ExecRulePurely(state->matched_by_patterns[i], ExecRulePurely(state->matched_by_patterns[i],
state->matched_text[i], state, 1); state->matched_text[i], state, true);
} }
void RuleMatcher::ExecPureRules(RuleEndpointState* state, bool eos) void RuleMatcher::ExecPureRules(RuleEndpointState* state, bool eos)
@ -1115,7 +1115,7 @@ void RuleMatcher::ExecRule(Rule* rule, RuleEndpointState* state, bool eos)
void RuleMatcher::ClearEndpointState(RuleEndpointState* state) void RuleMatcher::ClearEndpointState(RuleEndpointState* state)
{ {
ExecPureRules(state, 1); ExecPureRules(state, true);
state->payload_size = -1; state->payload_size = -1;

View file

@ -43,7 +43,7 @@ enum NetBIOS_Service {
NetSessions* sessions; NetSessions* sessions;
void IPTunnelTimer::Dispatch(double t, int is_expire) void IPTunnelTimer::Dispatch(double t, bool is_expire)
{ {
NetSessions::IPTunnelMap::const_iterator it = NetSessions::IPTunnelMap::const_iterator it =
sessions->ip_tunnels.find(tunnel_idx); sessions->ip_tunnels.find(tunnel_idx);
@ -360,7 +360,7 @@ void NetSessions::DoNextPacket(double t, const Packet* pkt, const IP_Hdr* ip_hdr
const struct tcphdr* tp = (const struct tcphdr *) data; const struct tcphdr* tp = (const struct tcphdr *) data;
id.src_port = tp->th_sport; id.src_port = tp->th_sport;
id.dst_port = tp->th_dport; id.dst_port = tp->th_dport;
id.is_one_way = 0; id.is_one_way = false;
d = &tcp_conns; d = &tcp_conns;
break; break;
} }
@ -370,7 +370,7 @@ void NetSessions::DoNextPacket(double t, const Packet* pkt, const IP_Hdr* ip_hdr
const struct udphdr* up = (const struct udphdr *) data; const struct udphdr* up = (const struct udphdr *) data;
id.src_port = up->uh_sport; id.src_port = up->uh_sport;
id.dst_port = up->uh_dport; id.dst_port = up->uh_dport;
id.is_one_way = 0; id.is_one_way = false;
d = &udp_conns; d = &udp_conns;
break; break;
} }
@ -681,7 +681,7 @@ void NetSessions::DoNextPacket(double t, const Packet* pkt, const IP_Hdr* ip_hdr
int record_packet = 1; // whether to record the packet at all int record_packet = 1; // whether to record the packet at all
int record_content = 1; // whether to record its data int record_content = 1; // whether to record its data
int is_orig = (id.src_addr == conn->OrigAddr()) && bool is_orig = (id.src_addr == conn->OrigAddr()) &&
(id.src_port == conn->OrigPort()); (id.src_port == conn->OrigPort());
conn->CheckFlowLabel(is_orig, ip_hdr->FlowLabel()); conn->CheckFlowLabel(is_orig, ip_hdr->FlowLabel());
@ -951,7 +951,7 @@ Connection* NetSessions::FindConnection(Val* v)
id.src_port = htons((unsigned short) orig_portv->Port()); id.src_port = htons((unsigned short) orig_portv->Port());
id.dst_port = htons((unsigned short) resp_portv->Port()); id.dst_port = htons((unsigned short) resp_portv->Port());
id.is_one_way = 0; // ### incorrect for ICMP connections id.is_one_way = false; // ### incorrect for ICMP connections
ConnIDKey key = BuildConnIDKey(id); ConnIDKey key = BuildConnIDKey(id);
ConnectionMap* d; ConnectionMap* d;

View file

@ -245,7 +245,7 @@ public:
~IPTunnelTimer() override {} ~IPTunnelTimer() override {}
void Dispatch(double t, int is_expire) override; void Dispatch(double t, bool is_expire) override;
protected: protected:
NetSessions::IPPair tunnel_idx; NetSessions::IPPair tunnel_idx;

View file

@ -31,14 +31,14 @@ public:
interval = i; interval = i;
} }
void Dispatch(double t, int is_expire); void Dispatch(double t, bool is_expire) override;
protected: protected:
double interval; double interval;
ProfileLogger* logger; ProfileLogger* logger;
}; };
void ProfileTimer::Dispatch(double t, int is_expire) void ProfileTimer::Dispatch(double t, bool is_expire)
{ {
logger->Log(); logger->Log();

View file

@ -83,9 +83,9 @@ bool Stmt::SetLocationInfo(const Location* start, const Location* end)
return true; return true;
} }
int Stmt::IsPure() const bool Stmt::IsPure() const
{ {
return 0; return false;
} }
void Stmt::Describe(ODesc* d) const void Stmt::Describe(ODesc* d) const
@ -267,7 +267,7 @@ IntrusivePtr<Val> PrintStmt::DoExec(std::vector<IntrusivePtr<Val>> vals,
if ( f->IsRawOutput() ) if ( f->IsRawOutput() )
{ {
ODesc d(DESC_READABLE); ODesc d(DESC_READABLE);
d.SetFlush(0); d.SetFlush(false);
d.SetStyle(style); d.SetStyle(style);
describe_vals(vals, &d, offset); describe_vals(vals, &d, offset);
@ -276,7 +276,7 @@ IntrusivePtr<Val> PrintStmt::DoExec(std::vector<IntrusivePtr<Val>> vals,
else else
{ {
ODesc d(DESC_READABLE, f); ODesc d(DESC_READABLE, f);
d.SetFlush(0); d.SetFlush(false);
d.SetStyle(style); d.SetStyle(style);
describe_vals(vals, &d, offset); describe_vals(vals, &d, offset);
@ -320,7 +320,7 @@ IntrusivePtr<Val> ExprStmt::DoExec(Frame* /* f */, Val* /* v */, stmt_flow_type&
return nullptr; return nullptr;
} }
int ExprStmt::IsPure() const bool ExprStmt::IsPure() const
{ {
return ! e || e->IsPure(); return ! e || e->IsPure();
} }
@ -396,7 +396,7 @@ IntrusivePtr<Val> IfStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const
return result; return result;
} }
int IfStmt::IsPure() const bool IfStmt::IsPure() const
{ {
return e->IsPure() && s1->IsPure() && s2->IsPure(); return e->IsPure() && s1->IsPure() && s2->IsPure();
} }
@ -718,7 +718,7 @@ SwitchStmt::~SwitchStmt()
bool SwitchStmt::AddCaseLabelValueMapping(const Val* v, int idx) bool SwitchStmt::AddCaseLabelValueMapping(const Val* v, int idx)
{ {
HashKey* hk = comp_hash->ComputeHash(v, 1); HashKey* hk = comp_hash->ComputeHash(v, true);
if ( ! hk ) if ( ! hk )
{ {
@ -762,7 +762,7 @@ std::pair<int, ID*> SwitchStmt::FindCaseLabelMatch(const Val* v) const
// Find matching expression cases. // Find matching expression cases.
if ( case_label_value_map.Length() ) if ( case_label_value_map.Length() )
{ {
HashKey* hk = comp_hash->ComputeHash(v, 1); HashKey* hk = comp_hash->ComputeHash(v, true);
if ( ! hk ) if ( ! hk )
{ {
@ -832,18 +832,18 @@ IntrusivePtr<Val> SwitchStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) con
return rval; return rval;
} }
int SwitchStmt::IsPure() const bool SwitchStmt::IsPure() const
{ {
if ( ! e->IsPure() ) if ( ! e->IsPure() )
return 0; return false;
for ( const auto& c : *cases ) for ( const auto& c : *cases )
{ {
if ( ! c->ExprCases()->IsPure() || ! c->Body()->IsPure() ) if ( ! c->ExprCases()->IsPure() || ! c->Body()->IsPure() )
return 0; return false;
} }
return 1; return true;
} }
void SwitchStmt::Describe(ODesc* d) const void SwitchStmt::Describe(ODesc* d) const
@ -889,9 +889,9 @@ AddStmt::AddStmt(IntrusivePtr<Expr> arg_e) : ExprStmt(STMT_ADD, std::move(arg_e)
Error("illegal add statement"); Error("illegal add statement");
} }
int AddStmt::IsPure() const bool AddStmt::IsPure() const
{ {
return 0; return false;
} }
IntrusivePtr<Val> AddStmt::Exec(Frame* f, stmt_flow_type& flow) const IntrusivePtr<Val> AddStmt::Exec(Frame* f, stmt_flow_type& flow) const
@ -925,9 +925,9 @@ DelStmt::DelStmt(IntrusivePtr<Expr> arg_e) : ExprStmt(STMT_DELETE, std::move(arg
Error("illegal delete statement"); Error("illegal delete statement");
} }
int DelStmt::IsPure() const bool DelStmt::IsPure() const
{ {
return 0; return false;
} }
IntrusivePtr<Val> DelStmt::Exec(Frame* f, stmt_flow_type& flow) const IntrusivePtr<Val> DelStmt::Exec(Frame* f, stmt_flow_type& flow) const
@ -993,7 +993,7 @@ WhileStmt::WhileStmt(IntrusivePtr<Expr> arg_loop_condition,
WhileStmt::~WhileStmt() = default; WhileStmt::~WhileStmt() = default;
int WhileStmt::IsPure() const bool WhileStmt::IsPure() const
{ {
return loop_condition->IsPure() && body->IsPure(); return loop_condition->IsPure() && body->IsPure();
} }
@ -1269,7 +1269,7 @@ IntrusivePtr<Val> ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const
return ret; return ret;
} }
int ForStmt::IsPure() const bool ForStmt::IsPure() const
{ {
return e->IsPure() && body->IsPure(); return e->IsPure() && body->IsPure();
} }
@ -1338,9 +1338,9 @@ IntrusivePtr<Val> NextStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const
return nullptr; return nullptr;
} }
int NextStmt::IsPure() const bool NextStmt::IsPure() const
{ {
return 1; return true;
} }
void NextStmt::Describe(ODesc* d) const void NextStmt::Describe(ODesc* d) const
@ -1365,9 +1365,9 @@ IntrusivePtr<Val> BreakStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const
return nullptr; return nullptr;
} }
int BreakStmt::IsPure() const bool BreakStmt::IsPure() const
{ {
return 1; return true;
} }
void BreakStmt::Describe(ODesc* d) const void BreakStmt::Describe(ODesc* d) const
@ -1392,9 +1392,9 @@ IntrusivePtr<Val> FallthroughStmt::Exec(Frame* /* f */, stmt_flow_type& flow) co
return nullptr; return nullptr;
} }
int FallthroughStmt::IsPure() const bool FallthroughStmt::IsPure() const
{ {
return 1; return false;
} }
void FallthroughStmt::Describe(ODesc* d) const void FallthroughStmt::Describe(ODesc* d) const
@ -1521,12 +1521,12 @@ IntrusivePtr<Val> StmtList::Exec(Frame* f, stmt_flow_type& flow) const
return nullptr; return nullptr;
} }
int StmtList::IsPure() const bool StmtList::IsPure() const
{ {
for ( const auto& stmt : stmts ) for ( const auto& stmt : stmts )
if ( ! stmt->IsPure() ) if ( ! stmt->IsPure() )
return 0; return false;
return 1; return true;
} }
void StmtList::Describe(ODesc* d) const void StmtList::Describe(ODesc* d) const
@ -1718,9 +1718,9 @@ IntrusivePtr<Val> NullStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const
return nullptr; return nullptr;
} }
int NullStmt::IsPure() const bool NullStmt::IsPure() const
{ {
return 1; return true;
} }
void NullStmt::Describe(ODesc* d) const void NullStmt::Describe(ODesc* d) const
@ -1780,7 +1780,7 @@ IntrusivePtr<Val> WhenStmt::Exec(Frame* f, stmt_flow_type& flow) const
return nullptr; return nullptr;
} }
int WhenStmt::IsPure() const bool WhenStmt::IsPure() const
{ {
return cond->IsPure() && s1->IsPure() && (! s2 || s2->IsPure()); return cond->IsPure() && s1->IsPure() && (! s2 || s2->IsPure());
} }

View file

@ -35,7 +35,7 @@ public:
bool SetLocationInfo(const Location* start, const Location* end) override; bool SetLocationInfo(const Location* start, const Location* end) override;
// True if the statement has no side effects, false otherwise. // True if the statement has no side effects, false otherwise.
virtual int IsPure() const; virtual bool IsPure() const;
StmtList* AsStmtList() StmtList* AsStmtList()
{ {
@ -131,7 +131,7 @@ protected:
virtual IntrusivePtr<Val> DoExec(Frame* f, Val* v, stmt_flow_type& flow) const; virtual IntrusivePtr<Val> DoExec(Frame* f, Val* v, stmt_flow_type& flow) const;
int IsPure() const override; bool IsPure() const override;
IntrusivePtr<Expr> e; IntrusivePtr<Expr> e;
}; };
@ -150,7 +150,7 @@ public:
protected: protected:
IntrusivePtr<Val> DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override; IntrusivePtr<Val> DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override;
int IsPure() const override; bool IsPure() const override;
IntrusivePtr<Stmt> s1; IntrusivePtr<Stmt> s1;
IntrusivePtr<Stmt> s2; IntrusivePtr<Stmt> s2;
@ -195,7 +195,7 @@ public:
protected: protected:
IntrusivePtr<Val> DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override; IntrusivePtr<Val> DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override;
int IsPure() const override; bool IsPure() const override;
// Initialize composite hash and case label map. // Initialize composite hash and case label map.
void Init(); void Init();
@ -227,7 +227,7 @@ class AddStmt : public ExprStmt {
public: public:
explicit AddStmt(IntrusivePtr<Expr> e); explicit AddStmt(IntrusivePtr<Expr> e);
int IsPure() const override; bool IsPure() const override;
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
@ -237,7 +237,7 @@ class DelStmt : public ExprStmt {
public: public:
explicit DelStmt(IntrusivePtr<Expr> e); explicit DelStmt(IntrusivePtr<Expr> e);
int IsPure() const override; bool IsPure() const override;
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
@ -261,7 +261,7 @@ public:
WhileStmt(IntrusivePtr<Expr> loop_condition, IntrusivePtr<Stmt> body); WhileStmt(IntrusivePtr<Expr> loop_condition, IntrusivePtr<Stmt> body);
~WhileStmt() override; ~WhileStmt() override;
int IsPure() const override; bool IsPure() const override;
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
@ -287,7 +287,7 @@ public:
const Expr* LoopExpr() const { return e.get(); } const Expr* LoopExpr() const { return e.get(); }
const Stmt* LoopBody() const { return body.get(); } const Stmt* LoopBody() const { return body.get(); }
int IsPure() const override; bool IsPure() const override;
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
@ -308,7 +308,7 @@ public:
NextStmt() : Stmt(STMT_NEXT) { } NextStmt() : Stmt(STMT_NEXT) { }
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
int IsPure() const override; bool IsPure() const override;
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
@ -322,7 +322,7 @@ public:
BreakStmt() : Stmt(STMT_BREAK) { } BreakStmt() : Stmt(STMT_BREAK) { }
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
int IsPure() const override; bool IsPure() const override;
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
@ -336,7 +336,7 @@ public:
FallthroughStmt() : Stmt(STMT_FALLTHROUGH) { } FallthroughStmt() : Stmt(STMT_FALLTHROUGH) { }
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
int IsPure() const override; bool IsPure() const override;
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
@ -369,7 +369,7 @@ public:
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
int IsPure() const override; bool IsPure() const override;
stmt_list stmts; stmt_list stmts;
}; };
@ -414,7 +414,7 @@ public:
NullStmt() : Stmt(STMT_NULL) { } NullStmt() : Stmt(STMT_NULL) { }
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
int IsPure() const override; bool IsPure() const override;
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
@ -430,7 +430,7 @@ public:
~WhenStmt() override; ~WhenStmt() override;
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
int IsPure() const override; bool IsPure() const override;
const Expr* Cond() const { return cond.get(); } const Expr* Cond() const { return cond.get(); }
const Stmt* Body() const { return s1.get(); } const Stmt* Body() const { return s1.get(); }

View file

@ -139,7 +139,7 @@ void PQ_TimerMgr::Expire()
{ {
DBG_LOG(DBG_TM, "Dispatching timer %s (%p)", DBG_LOG(DBG_TM, "Dispatching timer %s (%p)",
timer_type_to_string(timer->Type()), timer); timer_type_to_string(timer->Type()), timer);
timer->Dispatch(t, 1); timer->Dispatch(t, true);
--current_timers[timer->Type()]; --current_timers[timer->Type()];
delete timer; delete timer;
} }
@ -161,7 +161,7 @@ int PQ_TimerMgr::DoAdvance(double new_t, int max_expire)
DBG_LOG(DBG_TM, "Dispatching timer %s (%p)", DBG_LOG(DBG_TM, "Dispatching timer %s (%p)",
timer_type_to_string(timer->Type()), timer); timer_type_to_string(timer->Type()), timer);
timer->Dispatch(new_t, 0); timer->Dispatch(new_t, false);
delete timer; delete timer;
timer = Top(); timer = Top();

View file

@ -57,7 +57,7 @@ public:
// t gives the dispatch time. is_expire is true if the // t gives the dispatch time. is_expire is true if the
// timer is being dispatched because we're expiring all // timer is being dispatched because we're expiring all
// pending timers. // pending timers.
virtual void Dispatch(double t, int is_expire) = 0; virtual void Dispatch(double t, bool is_expire) = 0;
void Describe(ODesc* d) const; void Describe(ODesc* d) const;

View file

@ -98,7 +98,7 @@ public:
~TriggerTimer() ~TriggerTimer()
{ Unref(trigger); } { Unref(trigger); }
void Dispatch(double t, int is_expire) void Dispatch(double t, bool is_expire) override
{ {
// The network_time may still have been zero when the // The network_time may still have been zero when the
// timer was instantiated. In this case, it fires // timer was instantiated. In this case, it fires

View file

@ -112,9 +112,9 @@ BroType* BroType::YieldType()
return nullptr; return nullptr;
} }
int BroType::HasField(const char* /* field */) const bool BroType::HasField(const char* /* field */) const
{ {
return 0; return false;
} }
BroType* BroType::FieldType(const char* /* field */) const BroType* BroType::FieldType(const char* /* field */) const
@ -157,12 +157,12 @@ TypeList::~TypeList()
Unref(type); Unref(type);
} }
int TypeList::AllMatch(const BroType* t, int is_init) const bool TypeList::AllMatch(const BroType* t, bool is_init) const
{ {
for ( const auto& type : types ) for ( const auto& type : types )
if ( ! same_type(type, t, is_init) ) if ( ! same_type(type, t, is_init) )
return 0; return false;
return 1; return true;
} }
void TypeList::Append(IntrusivePtr<BroType> t) void TypeList::Append(IntrusivePtr<BroType> t)
@ -498,7 +498,7 @@ int FuncType::MatchesIndex(ListExpr* const index) const
MATCHES_INDEX_SCALAR : DOES_NOT_MATCH_INDEX; MATCHES_INDEX_SCALAR : DOES_NOT_MATCH_INDEX;
} }
int FuncType::CheckArgs(const type_list* args, bool is_init) const bool FuncType::CheckArgs(const type_list* args, bool is_init) const
{ {
const type_list* my_args = arg_types->Types(); const type_list* my_args = arg_types->Types();
@ -506,17 +506,17 @@ int FuncType::CheckArgs(const type_list* args, bool is_init) const
{ {
Warn(fmt("Wrong number of arguments for function. Expected %d, got %d.", Warn(fmt("Wrong number of arguments for function. Expected %d, got %d.",
args->length(), my_args->length())); args->length(), my_args->length()));
return 0; return false;
} }
int success = 1; bool success = true;
for ( int i = 0; i < my_args->length(); ++i ) for ( int i = 0; i < my_args->length(); ++i )
if ( ! same_type((*args)[i], (*my_args)[i], is_init) ) if ( ! same_type((*args)[i], (*my_args)[i], is_init) )
{ {
Warn(fmt("Type mismatch in function argument #%d. Expected %s, got %s.", Warn(fmt("Type mismatch in function argument #%d. Expected %s, got %s.",
i, type_name((*args)[i]->Tag()), type_name((*my_args)[i]->Tag()))); i, type_name((*args)[i]->Tag()), type_name((*my_args)[i]->Tag())));
success = 0; success = false;
} }
return success; return success;
@ -640,7 +640,7 @@ RecordType::~RecordType()
} }
} }
int RecordType::HasField(const char* field) const bool RecordType::HasField(const char* field) const
{ {
return FieldOffset(field) >= 0; return FieldOffset(field) >= 0;
} }
@ -1410,40 +1410,40 @@ BroType* base_type_no_ref(TypeTag tag)
// false otherwise. Assumes that t1's tag is different from t2's. Note // false otherwise. Assumes that t1's tag is different from t2's. Note
// that the test is in only one direction - we don't check whether t2 is // that the test is in only one direction - we don't check whether t2 is
// initialization-compatible with t1. // initialization-compatible with t1.
static int is_init_compat(const BroType* t1, const BroType* t2) static bool is_init_compat(const BroType* t1, const BroType* t2)
{ {
if ( t1->Tag() == TYPE_LIST ) if ( t1->Tag() == TYPE_LIST )
{ {
if ( t2->Tag() == TYPE_RECORD ) if ( t2->Tag() == TYPE_RECORD )
return 1; return true;
else else
return t1->AsTypeList()->AllMatch(t2, 1); return t1->AsTypeList()->AllMatch(t2, true);
} }
if ( t1->IsSet() ) if ( t1->IsSet() )
return same_type(t1->AsSetType()->Indices(), t2, 1); return same_type(t1->AsSetType()->Indices(), t2, true);
return 0; return false;
} }
int same_type(const BroType* t1, const BroType* t2, int is_init, bool match_record_field_names) bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_record_field_names)
{ {
if ( t1 == t2 || if ( t1 == t2 ||
t1->Tag() == TYPE_ANY || t1->Tag() == TYPE_ANY ||
t2->Tag() == TYPE_ANY ) t2->Tag() == TYPE_ANY )
return 1; return true;
t1 = flatten_type(t1); t1 = flatten_type(t1);
t2 = flatten_type(t2); t2 = flatten_type(t2);
if ( t1 == t2 ) if ( t1 == t2 )
return 1; return true;
if ( t1->Tag() != t2->Tag() ) if ( t1->Tag() != t2->Tag() )
{ {
if ( is_init ) if ( is_init )
return is_init_compat(t1, t2) || is_init_compat(t2, t1); return is_init_compat(t1, t2) || is_init_compat(t2, t1);
return 0; return false;
} }
switch ( t1->Tag() ) { switch ( t1->Tag() ) {
@ -1463,14 +1463,14 @@ int same_type(const BroType* t1, const BroType* t2, int is_init, bool match_reco
case TYPE_SUBNET: case TYPE_SUBNET:
case TYPE_ANY: case TYPE_ANY:
case TYPE_ERROR: case TYPE_ERROR:
return 1; return true;
case TYPE_ENUM: case TYPE_ENUM:
// We should probably check to see whether all of the // We should probably check to see whether all of the
// enumerations are present and in the same location. // enumerations are present and in the same location.
// FIXME: Yes, but perhaps we should better return // FIXME: Yes, but perhaps we should better return
// true per default? // true per default?
return 1; return true;
case TYPE_TABLE: case TYPE_TABLE:
{ {
@ -1483,7 +1483,7 @@ int same_type(const BroType* t1, const BroType* t2, int is_init, bool match_reco
if ( tl1 || tl2 ) if ( tl1 || tl2 )
{ {
if ( ! tl1 || ! tl2 || ! same_type(tl1, tl2, is_init, match_record_field_names) ) if ( ! tl1 || ! tl2 || ! same_type(tl1, tl2, is_init, match_record_field_names) )
return 0; return false;
} }
const BroType* y1 = t1->YieldType(); const BroType* y1 = t1->YieldType();
@ -1492,10 +1492,10 @@ int same_type(const BroType* t1, const BroType* t2, int is_init, bool match_reco
if ( y1 || y2 ) if ( y1 || y2 )
{ {
if ( ! y1 || ! y2 || ! same_type(y1, y2, is_init, match_record_field_names) ) if ( ! y1 || ! y2 || ! same_type(y1, y2, is_init, match_record_field_names) )
return 0; return false;
} }
return 1; return true;
} }
case TYPE_FUNC: case TYPE_FUNC:
@ -1504,13 +1504,13 @@ int same_type(const BroType* t1, const BroType* t2, int is_init, bool match_reco
const FuncType* ft2 = (const FuncType*) t2; const FuncType* ft2 = (const FuncType*) t2;
if ( ft1->Flavor() != ft2->Flavor() ) if ( ft1->Flavor() != ft2->Flavor() )
return 0; return false;
if ( t1->YieldType() || t2->YieldType() ) if ( t1->YieldType() || t2->YieldType() )
{ {
if ( ! t1->YieldType() || ! t2->YieldType() || if ( ! t1->YieldType() || ! t2->YieldType() ||
! same_type(t1->YieldType(), t2->YieldType(), is_init, match_record_field_names) ) ! same_type(t1->YieldType(), t2->YieldType(), is_init, match_record_field_names) )
return 0; return false;
} }
return ft1->CheckArgs(ft2->ArgTypes()->Types(), is_init); return ft1->CheckArgs(ft2->ArgTypes()->Types(), is_init);
@ -1522,7 +1522,7 @@ int same_type(const BroType* t1, const BroType* t2, int is_init, bool match_reco
const RecordType* rt2 = (const RecordType*) t2; const RecordType* rt2 = (const RecordType*) t2;
if ( rt1->NumFields() != rt2->NumFields() ) if ( rt1->NumFields() != rt2->NumFields() )
return 0; return false;
for ( int i = 0; i < rt1->NumFields(); ++i ) for ( int i = 0; i < rt1->NumFields(); ++i )
{ {
@ -1531,10 +1531,10 @@ int same_type(const BroType* t1, const BroType* t2, int is_init, bool match_reco
if ( (match_record_field_names && ! streq(td1->id, td2->id)) || if ( (match_record_field_names && ! streq(td1->id, td2->id)) ||
! same_type(td1->type.get(), td2->type.get(), is_init, match_record_field_names) ) ! same_type(td1->type.get(), td2->type.get(), is_init, match_record_field_names) )
return 0; return false;
} }
return 1; return true;
} }
case TYPE_LIST: case TYPE_LIST:
@ -1543,13 +1543,13 @@ int same_type(const BroType* t1, const BroType* t2, int is_init, bool match_reco
const type_list* tl2 = t2->AsTypeList()->Types(); const type_list* tl2 = t2->AsTypeList()->Types();
if ( tl1->length() != tl2->length() ) if ( tl1->length() != tl2->length() )
return 0; return false;
loop_over_list(*tl1, i) loop_over_list(*tl1, i)
if ( ! same_type((*tl1)[i], (*tl2)[i], is_init, match_record_field_names) ) if ( ! same_type((*tl1)[i], (*tl2)[i], is_init, match_record_field_names) )
return 0; return false;
return 1; return true;
} }
case TYPE_VECTOR: case TYPE_VECTOR:
@ -1560,7 +1560,7 @@ int same_type(const BroType* t1, const BroType* t2, int is_init, bool match_reco
{ {
const OpaqueType* ot1 = (const OpaqueType*) t1; const OpaqueType* ot1 = (const OpaqueType*) t1;
const OpaqueType* ot2 = (const OpaqueType*) t2; const OpaqueType* ot2 = (const OpaqueType*) t2;
return ot1->Name() == ot2->Name() ? 1 : 0; return ot1->Name() == ot2->Name();
} }
case TYPE_TYPE: case TYPE_TYPE:
@ -1569,10 +1569,10 @@ int same_type(const BroType* t1, const BroType* t2, int is_init, bool match_reco
case TYPE_UNION: case TYPE_UNION:
reporter->Error("union type in same_type()"); reporter->Error("union type in same_type()");
} }
return 0; return false;
} }
int same_attrs(const Attributes* a1, const Attributes* a2) bool same_attrs(const Attributes* a1, const Attributes* a2)
{ {
if ( ! a1 ) if ( ! a1 )
return (a2 == 0); return (a2 == 0);
@ -1583,7 +1583,7 @@ int same_attrs(const Attributes* a1, const Attributes* a2)
return (*a1 == *a2); return (*a1 == *a2);
} }
int record_promotion_compatible(const RecordType* super_rec, bool record_promotion_compatible(const RecordType* super_rec,
const RecordType* sub_rec) const RecordType* sub_rec)
{ {
for ( int i = 0; i < sub_rec->NumFields(); ++i ) for ( int i = 0; i < sub_rec->NumFields(); ++i )
@ -1601,17 +1601,17 @@ int record_promotion_compatible(const RecordType* super_rec,
continue; continue;
if ( sub_field_type->Tag() != TYPE_RECORD ) if ( sub_field_type->Tag() != TYPE_RECORD )
return 0; return false;
if ( super_field_type->Tag() != TYPE_RECORD ) if ( super_field_type->Tag() != TYPE_RECORD )
return 0; return false;
if ( ! record_promotion_compatible(super_field_type->AsRecordType(), if ( ! record_promotion_compatible(super_field_type->AsRecordType(),
sub_field_type->AsRecordType()) ) sub_field_type->AsRecordType()) )
return 0; return false;
} }
return 1; return true;
} }
const BroType* flatten_type(const BroType* t) const BroType* flatten_type(const BroType* t)
@ -1630,7 +1630,7 @@ const BroType* flatten_type(const BroType* t)
reporter->InternalError("empty type list in flatten_type"); reporter->InternalError("empty type list in flatten_type");
const BroType* ft = (*types)[0]; const BroType* ft = (*types)[0];
if ( types->length() == 1 || tl->AllMatch(ft, 0) ) if ( types->length() == 1 || tl->AllMatch(ft, false) )
return ft; return ft;
return t; return t;
@ -1641,7 +1641,7 @@ BroType* flatten_type(BroType* t)
return (BroType*) flatten_type((const BroType*) t); return (BroType*) flatten_type((const BroType*) t);
} }
int is_assignable(BroType* t) bool is_assignable(BroType* t)
{ {
switch ( t->Tag() ) { switch ( t->Tag() ) {
case TYPE_BOOL: case TYPE_BOOL:
@ -1663,23 +1663,23 @@ int is_assignable(BroType* t)
case TYPE_ANY: case TYPE_ANY:
case TYPE_ERROR: case TYPE_ERROR:
case TYPE_LIST: case TYPE_LIST:
return 1; return true;
case TYPE_VECTOR: case TYPE_VECTOR:
case TYPE_FILE: case TYPE_FILE:
case TYPE_OPAQUE: case TYPE_OPAQUE:
case TYPE_TABLE: case TYPE_TABLE:
case TYPE_TYPE: case TYPE_TYPE:
return 1; return true;
case TYPE_VOID: case TYPE_VOID:
return 0; return false;
case TYPE_UNION: case TYPE_UNION:
reporter->Error("union type in is_assignable()"); reporter->Error("union type in is_assignable()");
} }
return 0; return false;
} }
#define CHECK_TYPE(t) \ #define CHECK_TYPE(t) \

View file

@ -156,7 +156,7 @@ public:
InternalTypeTag InternalType() const { return internal_tag; } InternalTypeTag InternalType() const { return internal_tag; }
// Whether it's stored in network order. // Whether it's stored in network order.
int IsNetworkOrder() const { return is_network_order; } bool IsNetworkOrder() const { return is_network_order; }
// Type-checks the given expression list, returning // Type-checks the given expression list, returning
// MATCHES_INDEX_SCALAR = 1 if it matches this type's index // MATCHES_INDEX_SCALAR = 1 if it matches this type's index
@ -176,7 +176,7 @@ public:
// Returns true if this type is a record and contains the // Returns true if this type is a record and contains the
// given field, false otherwise. // given field, false otherwise.
virtual int HasField(const char* field) const; virtual bool HasField(const char* field) const;
// Returns the type of the given field, or nil if no such field. // Returns the type of the given field, or nil if no such field.
virtual BroType* FieldType(const char* field) const; virtual BroType* FieldType(const char* field) const;
@ -357,7 +357,7 @@ public:
const type_list* Types() const { return &types; } const type_list* Types() const { return &types; }
type_list* Types() { return &types; } type_list* Types() { return &types; }
int IsPure() const { return pure_type != 0; } bool IsPure() const { return pure_type != 0; }
// Returns the underlying pure type, or nil if the list // Returns the underlying pure type, or nil if the list
// is not pure or is empty. // is not pure or is empty.
@ -367,7 +367,7 @@ public:
// True if all of the types match t, false otherwise. If // True if all of the types match t, false otherwise. If
// is_init is true, then the matching is done in the context // is_init is true, then the matching is done in the context
// of an initialization. // of an initialization.
int AllMatch(const BroType* t, int is_init) const; bool AllMatch(const BroType* t, bool is_init) const;
void Append(IntrusivePtr<BroType> t); void Append(IntrusivePtr<BroType> t);
void AppendEvenIfNotPure(IntrusivePtr<BroType> t); void AppendEvenIfNotPure(IntrusivePtr<BroType> t);
@ -457,7 +457,7 @@ public:
{ yield = nullptr; flavor = arg_flav; } { yield = nullptr; flavor = arg_flav; }
int MatchesIndex(ListExpr* index) const override; int MatchesIndex(ListExpr* index) const override;
int CheckArgs(const type_list* args, bool is_init = false) const; bool CheckArgs(const type_list* args, bool is_init = false) const;
TypeList* ArgTypes() const { return arg_types.get(); } TypeList* ArgTypes() const { return arg_types.get(); }
@ -508,7 +508,7 @@ public:
~RecordType() override; ~RecordType() override;
int HasField(const char* field) const override; bool HasField(const char* field) const override;
BroType* FieldType(const char* field) const override; BroType* FieldType(const char* field) const override;
BroType* FieldType(int field) const; BroType* FieldType(int field) const;
IntrusivePtr<Val> FieldDefault(int field) const; IntrusivePtr<Val> FieldDefault(int field) const;
@ -702,14 +702,14 @@ inline IntrusivePtr<BroType> error_type() { return base_type(TYPE_ERROR); }
// True if the two types are equivalent. If is_init is true then the test is // True if the two types are equivalent. If is_init is true then the test is
// done in the context of an initialization. If match_record_field_names is // done in the context of an initialization. If match_record_field_names is
// true then for record types the field names have to match, too. // true then for record types the field names have to match, too.
extern int same_type(const BroType* t1, const BroType* t2, int is_init=0, bool match_record_field_names=true); extern bool same_type(const BroType* t1, const BroType* t2, bool is_init=false, bool match_record_field_names=true);
// True if the two attribute lists are equivalent. // True if the two attribute lists are equivalent.
extern int same_attrs(const Attributes* a1, const Attributes* a2); extern bool same_attrs(const Attributes* a1, const Attributes* a2);
// Returns true if the record sub_rec can be promoted to the record // Returns true if the record sub_rec can be promoted to the record
// super_rec. // super_rec.
extern int record_promotion_compatible(const RecordType* super_rec, extern bool record_promotion_compatible(const RecordType* super_rec,
const RecordType* sub_rec); const RecordType* sub_rec);
// If the given BroType is a TypeList with just one element, returns // If the given BroType is a TypeList with just one element, returns
@ -737,7 +737,7 @@ IntrusivePtr<BroType> init_type(Expr* init);
bool is_atomic_type(const BroType* t); bool is_atomic_type(const BroType* t);
// True if the given type tag corresponds to type that can be assigned to. // True if the given type tag corresponds to type that can be assigned to.
extern int is_assignable(BroType* t); extern bool is_assignable(BroType* t);
// True if the given type tag corresponds to an integral type. // True if the given type tag corresponds to an integral type.
inline bool IsIntegral(TypeTag t) { return (t == TYPE_INT || t == TYPE_COUNT || t == TYPE_COUNTER); } inline bool IsIntegral(TypeTag t) { return (t == TYPE_INT || t == TYPE_COUNT || t == TYPE_COUNTER); }

View file

@ -144,25 +144,25 @@ IntrusivePtr<Val> Val::DoClone(CloneState* state)
return nullptr; return nullptr;
} }
int Val::IsZero() const bool Val::IsZero() const
{ {
switch ( type->InternalType() ) { switch ( type->InternalType() ) {
case TYPE_INTERNAL_INT: return val.int_val == 0; case TYPE_INTERNAL_INT: return val.int_val == 0;
case TYPE_INTERNAL_UNSIGNED: return val.uint_val == 0; case TYPE_INTERNAL_UNSIGNED: return val.uint_val == 0;
case TYPE_INTERNAL_DOUBLE: return val.double_val == 0.0; case TYPE_INTERNAL_DOUBLE: return val.double_val == 0.0;
default: return 0; default: return false;
} }
} }
int Val::IsOne() const bool Val::IsOne() const
{ {
switch ( type->InternalType() ) { switch ( type->InternalType() ) {
case TYPE_INTERNAL_INT: return val.int_val == 1; case TYPE_INTERNAL_INT: return val.int_val == 1;
case TYPE_INTERNAL_UNSIGNED: return val.uint_val == 1; case TYPE_INTERNAL_UNSIGNED: return val.uint_val == 1;
case TYPE_INTERNAL_DOUBLE: return val.double_val == 1.0; case TYPE_INTERNAL_DOUBLE: return val.double_val == 1.0;
default: return 0; default: return false;
} }
} }
@ -278,16 +278,16 @@ unsigned int Val::MemoryAllocation() const
return padded_sizeof(*this); return padded_sizeof(*this);
} }
int Val::AddTo(Val* v, int is_first_init) const bool Val::AddTo(Val* v, bool is_first_init) const
{ {
Error("+= initializer only applies to aggregate values"); Error("+= initializer only applies to aggregate values");
return 0; return false;
} }
int Val::RemoveFrom(Val* v) const bool Val::RemoveFrom(Val* v) const
{ {
Error("-= initializer only applies to aggregate values"); Error("-= initializer only applies to aggregate values");
return 0; return false;
} }
void Val::Describe(ODesc* d) const void Val::Describe(ODesc* d) const
@ -581,7 +581,7 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val*
{ {
auto blank = make_intrusive<StringVal>(""); auto blank = make_intrusive<StringVal>("");
auto fn_val = make_intrusive<StringVal>(field_name); auto fn_val = make_intrusive<StringVal>(field_name);
auto key_val = fn_val->Substitute(re, blank.get(), 0)->AsStringVal(); auto key_val = fn_val->Substitute(re, blank.get(), false)->AsStringVal();
key_str = key_val->ToStdString(); key_str = key_val->ToStdString();
Unref(key_val); Unref(key_val);
} }
@ -786,17 +786,17 @@ string PortVal::Protocol() const
return "unknown"; return "unknown";
} }
int PortVal::IsTCP() const bool PortVal::IsTCP() const
{ {
return (val.uint_val & PORT_SPACE_MASK) == TCP_PORT_MASK; return (val.uint_val & PORT_SPACE_MASK) == TCP_PORT_MASK;
} }
int PortVal::IsUDP() const bool PortVal::IsUDP() const
{ {
return (val.uint_val & PORT_SPACE_MASK) == UDP_PORT_MASK; return (val.uint_val & PORT_SPACE_MASK) == UDP_PORT_MASK;
} }
int PortVal::IsICMP() const bool PortVal::IsICMP() const
{ {
return (val.uint_val & PORT_SPACE_MASK) == ICMP_PORT_MASK; return (val.uint_val & PORT_SPACE_MASK) == ICMP_PORT_MASK;
} }
@ -963,7 +963,7 @@ StringVal::StringVal(BroString* s) : Val(s, TYPE_STRING)
// The following adds a NUL at the end. // The following adds a NUL at the end.
StringVal::StringVal(int length, const char* s) StringVal::StringVal(int length, const char* s)
: StringVal(new BroString(reinterpret_cast<const u_char*>(s), length, 1)) : StringVal(new BroString(reinterpret_cast<const u_char*>(s), length, true))
{ {
} }
@ -1103,7 +1103,7 @@ Val* StringVal::Substitute(RE_Matcher* re, StringVal* repl, bool do_all)
// the NUL. // the NUL.
r[0] = '\0'; r[0] = '\0';
return new StringVal(new BroString(1, result, r - result)); return new StringVal(new BroString(true, result, r - result));
} }
IntrusivePtr<Val> StringVal::DoClone(CloneState* state) IntrusivePtr<Val> StringVal::DoClone(CloneState* state)
@ -1113,7 +1113,7 @@ IntrusivePtr<Val> StringVal::DoClone(CloneState* state)
// audit whether anything internal actually does mutate it. // audit whether anything internal actually does mutate it.
return state->NewClone(this, make_intrusive<StringVal>( return state->NewClone(this, make_intrusive<StringVal>(
new BroString((u_char*) val.string_val->Bytes(), new BroString((u_char*) val.string_val->Bytes(),
val.string_val->Len(), 1))); val.string_val->Len(), true)));
} }
PatternVal::PatternVal(RE_Matcher* re) PatternVal::PatternVal(RE_Matcher* re)
@ -1128,12 +1128,12 @@ PatternVal::~PatternVal()
Unref(type); // base_type() ref'd it, so did our base constructor Unref(type); // base_type() ref'd it, so did our base constructor
} }
int PatternVal::AddTo(Val* v, int /* is_first_init */) const bool PatternVal::AddTo(Val* v, bool /* is_first_init */) const
{ {
if ( v->Type()->Tag() != TYPE_PATTERN ) if ( v->Type()->Tag() != TYPE_PATTERN )
{ {
v->Error("not a pattern"); v->Error("not a pattern");
return 0; return false;
} }
PatternVal* pv = v->AsPatternVal(); PatternVal* pv = v->AsPatternVal();
@ -1144,7 +1144,7 @@ int PatternVal::AddTo(Val* v, int /* is_first_init */) const
pv->SetMatcher(re); pv->SetMatcher(re);
return 1; return true;
} }
void PatternVal::SetMatcher(RE_Matcher* re) void PatternVal::SetMatcher(RE_Matcher* re)
@ -1303,7 +1303,7 @@ TableValTimer::~TableValTimer()
table->ClearTimer(this); table->ClearTimer(this);
} }
void TableValTimer::Dispatch(double t, int is_expire) void TableValTimer::Dispatch(double t, bool is_expire)
{ {
if ( ! is_expire ) if ( ! is_expire )
{ {
@ -1491,26 +1491,26 @@ void TableVal::CheckExpireAttr(attr_tag at)
} }
} }
int TableVal::Assign(Val* index, IntrusivePtr<Val> new_val) bool TableVal::Assign(Val* index, IntrusivePtr<Val> new_val)
{ {
HashKey* k = ComputeHash(index); HashKey* k = ComputeHash(index);
if ( ! k ) if ( ! k )
{ {
index->Error("index type doesn't match table", table_type->Indices()); index->Error("index type doesn't match table", table_type->Indices());
return 0; return false;
} }
return Assign(index, k, std::move(new_val)); return Assign(index, k, std::move(new_val));
} }
int TableVal::Assign(Val* index, Val* new_val) bool TableVal::Assign(Val* index, Val* new_val)
{ {
return Assign(index, {AdoptRef{}, new_val}); return Assign(index, {AdoptRef{}, new_val});
} }
int TableVal::Assign(Val* index, HashKey* k, IntrusivePtr<Val> new_val) bool TableVal::Assign(Val* index, HashKey* k, IntrusivePtr<Val> new_val)
{ {
int is_set = table_type->IsSet(); bool is_set = table_type->IsSet();
if ( (is_set && new_val) || (! is_set && ! new_val) ) if ( (is_set && new_val) || (! is_set && ! new_val) )
InternalWarning("bad set/table in TableVal::Assign"); InternalWarning("bad set/table in TableVal::Assign");
@ -1523,7 +1523,7 @@ int TableVal::Assign(Val* index, HashKey* k, IntrusivePtr<Val> new_val)
// memory allocated to the key bytes, so have to assume k is invalid // memory allocated to the key bytes, so have to assume k is invalid
// from here on out. // from here on out.
delete k; delete k;
k = 0; k = nullptr;
if ( subnets ) if ( subnets )
{ {
@ -1552,10 +1552,10 @@ int TableVal::Assign(Val* index, HashKey* k, IntrusivePtr<Val> new_val)
delete old_entry_val; delete old_entry_val;
return 1; return true;
} }
int TableVal::Assign(Val* index, HashKey* k, Val* new_val) bool TableVal::Assign(Val* index, HashKey* k, Val* new_val)
{ {
return Assign(index, k, {AdoptRef{}, new_val}); return Assign(index, k, {AdoptRef{}, new_val});
} }
@ -1565,17 +1565,17 @@ IntrusivePtr<Val> TableVal::SizeVal() const
return {AdoptRef{}, val_mgr->GetCount(Size())}; return {AdoptRef{}, val_mgr->GetCount(Size())};
} }
int TableVal::AddTo(Val* val, int is_first_init) const bool TableVal::AddTo(Val* val, bool is_first_init) const
{ {
return AddTo(val, is_first_init, true); return AddTo(val, is_first_init, true);
} }
int TableVal::AddTo(Val* val, int is_first_init, bool propagate_ops) const bool TableVal::AddTo(Val* val, bool is_first_init, bool propagate_ops) const
{ {
if ( val->Type()->Tag() != TYPE_TABLE ) if ( val->Type()->Tag() != TYPE_TABLE )
{ {
val->Error("not a table"); val->Error("not a table");
return 0; return false;
} }
TableVal* t = val->AsTableVal(); TableVal* t = val->AsTableVal();
@ -1583,7 +1583,7 @@ int TableVal::AddTo(Val* val, int is_first_init, bool propagate_ops) const
if ( ! same_type(type, t->Type()) ) if ( ! same_type(type, t->Type()) )
{ {
type->Error("table type clash", t->Type()); type->Error("table type clash", t->Type());
return 0; return false;
} }
const PDict<TableEntryVal>* tbl = AsTable(); const PDict<TableEntryVal>* tbl = AsTable();
@ -1604,24 +1604,24 @@ int TableVal::AddTo(Val* val, int is_first_init, bool propagate_ops) const
if ( type->IsSet() ) if ( type->IsSet() )
{ {
if ( ! t->Assign(v->Value(), k, 0) ) if ( ! t->Assign(v->Value(), k, 0) )
return 0; return false;
} }
else else
{ {
if ( ! t->Assign(0, k, {NewRef{}, v->Value()}) ) if ( ! t->Assign(0, k, {NewRef{}, v->Value()}) )
return 0; return false;
} }
} }
return 1; return true;
} }
int TableVal::RemoveFrom(Val* val) const bool TableVal::RemoveFrom(Val* val) const
{ {
if ( val->Type()->Tag() != TYPE_TABLE ) if ( val->Type()->Tag() != TYPE_TABLE )
{ {
val->Error("not a table"); val->Error("not a table");
return 0; return false;
} }
TableVal* t = val->AsTableVal(); TableVal* t = val->AsTableVal();
@ -1629,7 +1629,7 @@ int TableVal::RemoveFrom(Val* val) const
if ( ! same_type(type, t->Type()) ) if ( ! same_type(type, t->Type()) )
{ {
type->Error("table type clash", t->Type()); type->Error("table type clash", t->Type());
return 0; return false;
} }
const PDict<TableEntryVal>* tbl = AsTable(); const PDict<TableEntryVal>* tbl = AsTable();
@ -1647,7 +1647,7 @@ int TableVal::RemoveFrom(Val* val) const
delete k; delete k;
} }
return 1; return true;
} }
TableVal* TableVal::Intersect(const TableVal* tv) const TableVal* TableVal::Intersect(const TableVal* tv) const
@ -1735,7 +1735,7 @@ bool TableVal::IsSubsetOf(const TableVal* tv) const
return true; return true;
} }
int TableVal::ExpandAndInit(IntrusivePtr<Val> index, IntrusivePtr<Val> new_val) bool TableVal::ExpandAndInit(IntrusivePtr<Val> index, IntrusivePtr<Val> new_val)
{ {
BroType* index_type = index->Type(); BroType* index_type = index->Type();
@ -1757,9 +1757,9 @@ int TableVal::ExpandAndInit(IntrusivePtr<Val> index, IntrusivePtr<Val> new_val)
for ( int i = 0; i < iv->Length(); ++i ) for ( int i = 0; i < iv->Length(); ++i )
if ( ! ExpandAndInit({NewRef{}, iv->Index(i)}, new_val) ) if ( ! ExpandAndInit({NewRef{}, iv->Index(i)}, new_val) )
return 0; return false;
return 1; return true;
} }
else else
@ -2225,7 +2225,7 @@ void TableVal::Describe(ODesc* d) const
} }
} }
int TableVal::ExpandCompoundAndInit(val_list* vl, int k, IntrusivePtr<Val> new_val) bool TableVal::ExpandCompoundAndInit(val_list* vl, int k, IntrusivePtr<Val> new_val)
{ {
Val* ind_k_v = (*vl)[k]; Val* ind_k_v = (*vl)[k];
auto ind_k = ind_k_v->Type()->IsSet() ? auto ind_k = ind_k_v->Type()->IsSet() ?
@ -2244,16 +2244,14 @@ int TableVal::ExpandCompoundAndInit(val_list* vl, int k, IntrusivePtr<Val> new_v
expd->Append((*vl)[j]->Ref()); expd->Append((*vl)[j]->Ref());
} }
int success = ExpandAndInit(std::move(expd), new_val); if ( ! ExpandAndInit(std::move(expd), new_val) )
return false;
if ( ! success )
return 0;
} }
return 1; return true;
} }
int TableVal::CheckAndAssign(Val* index, IntrusivePtr<Val> new_val) bool TableVal::CheckAndAssign(Val* index, IntrusivePtr<Val> new_val)
{ {
Val* v = 0; Val* v = 0;
if ( subnets ) if ( subnets )
@ -2559,7 +2557,7 @@ unsigned int TableVal::MemoryAllocation() const
HashKey* TableVal::ComputeHash(const Val* index) const HashKey* TableVal::ComputeHash(const Val* index) const
{ {
return table_hash->ComputeHash(index, 1); return table_hash->ComputeHash(index, true);
} }
void TableVal::SaveParseTimeTableState(RecordType* rt) void TableVal::SaveParseTimeTableState(RecordType* rt)
@ -2974,7 +2972,7 @@ IntrusivePtr<Val> VectorVal::SizeVal() const
bool VectorVal::Assign(unsigned int index, IntrusivePtr<Val> element) bool VectorVal::Assign(unsigned int index, IntrusivePtr<Val> element)
{ {
if ( element && if ( element &&
! same_type(element->Type(), vector_type->YieldType(), 0) ) ! same_type(element->Type(), vector_type->YieldType(), false) )
return false; return false;
Val* val_at_index = 0; Val* val_at_index = 0;
@ -3015,7 +3013,7 @@ bool VectorVal::AssignRepeat(unsigned int index, unsigned int how_many,
bool VectorVal::Insert(unsigned int index, Val* element) bool VectorVal::Insert(unsigned int index, Val* element)
{ {
if ( element && if ( element &&
! same_type(element->Type(), vector_type->YieldType(), 0) ) ! same_type(element->Type(), vector_type->YieldType(), false) )
{ {
Unref(element); Unref(element);
return false; return false;
@ -3051,12 +3049,12 @@ bool VectorVal::Remove(unsigned int index)
return true; return true;
} }
int VectorVal::AddTo(Val* val, int /* is_first_init */) const bool VectorVal::AddTo(Val* val, bool /* is_first_init */) const
{ {
if ( val->Type()->Tag() != TYPE_VECTOR ) if ( val->Type()->Tag() != TYPE_VECTOR )
{ {
val->Error("not a vector"); val->Error("not a vector");
return 0; return false;
} }
VectorVal* v = val->AsVectorVal(); VectorVal* v = val->AsVectorVal();
@ -3064,7 +3062,7 @@ int VectorVal::AddTo(Val* val, int /* is_first_init */) const
if ( ! same_type(type, v->Type()) ) if ( ! same_type(type, v->Type()) )
{ {
type->Error("vector type clash", v->Type()); type->Error("vector type clash", v->Type());
return 0; return false;
} }
auto last_idx = v->Size(); auto last_idx = v->Size();
@ -3072,7 +3070,7 @@ int VectorVal::AddTo(Val* val, int /* is_first_init */) const
for ( auto i = 0u; i < Size(); ++i ) for ( auto i = 0u; i < Size(); ++i )
v->Assign(last_idx++, {NewRef{}, Lookup(i)}); v->Assign(last_idx++, {NewRef{}, Lookup(i)});
return 1; return true;
} }
Val* VectorVal::Lookup(unsigned int index) const Val* VectorVal::Lookup(unsigned int index) const
@ -3135,7 +3133,7 @@ void VectorVal::ValDescribe(ODesc* d) const
} }
IntrusivePtr<Val> check_and_promote(IntrusivePtr<Val> v, const BroType* t, IntrusivePtr<Val> check_and_promote(IntrusivePtr<Val> v, const BroType* t,
int is_init, bool is_init,
const Location* expr_location) const Location* expr_location)
{ {
if ( ! v ) if ( ! v )
@ -3160,7 +3158,7 @@ IntrusivePtr<Val> check_and_promote(IntrusivePtr<Val> v, const BroType* t,
if ( same_type(t, vt, is_init) ) if ( same_type(t, vt, is_init) )
return v; return v;
t->Error("type clash", v.get(), 0, expr_location); t->Error("type clash", v.get(), false, expr_location);
return nullptr; return nullptr;
} }
@ -3168,9 +3166,9 @@ IntrusivePtr<Val> check_and_promote(IntrusivePtr<Val> v, const BroType* t,
(! IsArithmetic(v_tag) || t_tag != TYPE_TIME || ! v->IsZero()) ) (! IsArithmetic(v_tag) || t_tag != TYPE_TIME || ! v->IsZero()) )
{ {
if ( t_tag == TYPE_LIST || v_tag == TYPE_LIST ) if ( t_tag == TYPE_LIST || v_tag == TYPE_LIST )
t->Error("list mixed with scalar", v.get(), 0, expr_location); t->Error("list mixed with scalar", v.get(), false, expr_location);
else else
t->Error("arithmetic mixed with non-arithmetic", v.get(), 0, expr_location); t->Error("arithmetic mixed with non-arithmetic", v.get(), false, expr_location);
return nullptr; return nullptr;
} }
@ -3182,7 +3180,7 @@ IntrusivePtr<Val> check_and_promote(IntrusivePtr<Val> v, const BroType* t,
TypeTag mt = max_type(t_tag, v_tag); TypeTag mt = max_type(t_tag, v_tag);
if ( mt != t_tag ) if ( mt != t_tag )
{ {
t->Error("over-promotion of arithmetic value", v.get(), 0, expr_location); t->Error("over-promotion of arithmetic value", v.get(), false, expr_location);
return nullptr; return nullptr;
} }
} }
@ -3201,7 +3199,7 @@ IntrusivePtr<Val> check_and_promote(IntrusivePtr<Val> v, const BroType* t,
case TYPE_INTERNAL_INT: case TYPE_INTERNAL_INT:
if ( ( vit == TYPE_INTERNAL_UNSIGNED || vit == TYPE_INTERNAL_DOUBLE ) && Val::WouldOverflow(vt, t, v.get()) ) if ( ( vit == TYPE_INTERNAL_UNSIGNED || vit == TYPE_INTERNAL_DOUBLE ) && Val::WouldOverflow(vt, t, v.get()) )
{ {
t->Error("overflow promoting from unsigned/double to signed arithmetic value", v.get(), 0, expr_location); t->Error("overflow promoting from unsigned/double to signed arithmetic value", v.get(), false, expr_location);
return nullptr; return nullptr;
} }
else if ( t_tag == TYPE_INT ) else if ( t_tag == TYPE_INT )
@ -3217,7 +3215,7 @@ IntrusivePtr<Val> check_and_promote(IntrusivePtr<Val> v, const BroType* t,
case TYPE_INTERNAL_UNSIGNED: case TYPE_INTERNAL_UNSIGNED:
if ( ( vit == TYPE_INTERNAL_DOUBLE || vit == TYPE_INTERNAL_INT) && Val::WouldOverflow(vt, t, v.get()) ) if ( ( vit == TYPE_INTERNAL_DOUBLE || vit == TYPE_INTERNAL_INT) && Val::WouldOverflow(vt, t, v.get()) )
{ {
t->Error("overflow promoting from signed/double to unsigned arithmetic value", v.get(), 0, expr_location); t->Error("overflow promoting from signed/double to unsigned arithmetic value", v.get(), false, expr_location);
return nullptr; return nullptr;
} }
else if ( t_tag == TYPE_COUNT || t_tag == TYPE_COUNTER ) else if ( t_tag == TYPE_COUNT || t_tag == TYPE_COUNTER )
@ -3242,10 +3240,10 @@ IntrusivePtr<Val> check_and_promote(IntrusivePtr<Val> v, const BroType* t,
return promoted_v; return promoted_v;
} }
int same_val(const Val* /* v1 */, const Val* /* v2 */) bool same_val(const Val* /* v1 */, const Val* /* v2 */)
{ {
reporter->InternalError("same_val not implemented"); reporter->InternalError("same_val not implemented");
return 0; return false;
} }
bool is_atomic_val(const Val* v) bool is_atomic_val(const Val* v)
@ -3253,12 +3251,12 @@ bool is_atomic_val(const Val* v)
return is_atomic_type(v->Type()); return is_atomic_type(v->Type());
} }
int same_atomic_val(const Val* v1, const Val* v2) bool same_atomic_val(const Val* v1, const Val* v2)
{ {
// This is a very preliminary implementation of same_val(), // This is a very preliminary implementation of same_val(),
// true only for equal, simple atomic values of same type. // true only for equal, simple atomic values of same type.
if ( v1->Type()->Tag() != v2->Type()->Tag() ) if ( v1->Type()->Tag() != v2->Type()->Tag() )
return 0; return false;
switch ( v1->Type()->InternalType() ) { switch ( v1->Type()->InternalType() ) {
case TYPE_INTERNAL_INT: case TYPE_INTERNAL_INT:
@ -3276,10 +3274,10 @@ int same_atomic_val(const Val* v1, const Val* v2)
default: default:
reporter->InternalWarning("same_atomic_val called for non-atomic value"); reporter->InternalWarning("same_atomic_val called for non-atomic value");
return 0; return false;
} }
return 0; return false;
} }
void describe_vals(const val_list* vals, ODesc* d, int offset) void describe_vals(const val_list* vals, ODesc* d, int offset)

View file

@ -155,8 +155,8 @@ public:
Val* Ref() { ::Ref(this); return this; } Val* Ref() { ::Ref(this); return this; }
IntrusivePtr<Val> Clone(); IntrusivePtr<Val> Clone();
int IsZero() const; bool IsZero() const;
int IsOne() const; bool IsOne() const;
bro_int_t InternalInt() const; bro_int_t InternalInt() const;
bro_uint_t InternalUnsigned() const; bro_uint_t InternalUnsigned() const;
@ -177,10 +177,10 @@ public:
// Returns true if succcessful. is_first_init is true only if // Returns true if succcessful. is_first_init is true only if
// this is the *first* initialization of the value, not // this is the *first* initialization of the value, not
// if it's a subsequent += initialization. // if it's a subsequent += initialization.
virtual int AddTo(Val* v, int is_first_init) const; virtual bool AddTo(Val* v, bool is_first_init) const;
// Remove this value from the given value (if appropriate). // Remove this value from the given value (if appropriate).
virtual int RemoveFrom(Val* v) const; virtual bool RemoveFrom(Val* v) const;
BroType* Type() { return type; } BroType* Type() { return type; }
const BroType* Type() const { return type; } const BroType* Type() const { return type; }
@ -478,9 +478,9 @@ public:
string Protocol() const; string Protocol() const;
// Tests for protocol types. // Tests for protocol types.
int IsTCP() const; bool IsTCP() const;
int IsUDP() const; bool IsUDP() const;
int IsICMP() const; bool IsICMP() const;
TransportProto PortType() const TransportProto PortType() const
{ {
@ -584,7 +584,7 @@ public:
explicit PatternVal(RE_Matcher* re); explicit PatternVal(RE_Matcher* re);
~PatternVal() override; ~PatternVal() override;
int AddTo(Val* v, int is_first_init) const override; bool AddTo(Val* v, bool is_first_init) const override;
void SetMatcher(RE_Matcher* re); void SetMatcher(RE_Matcher* re);
@ -679,7 +679,7 @@ public:
TableValTimer(TableVal* val, double t); TableValTimer(TableVal* val, double t);
~TableValTimer() override; ~TableValTimer() override;
void Dispatch(double t, int is_expire) override; void Dispatch(double t, bool is_expire) override;
TableVal* Table() { return table; } TableVal* Table() { return table; }
@ -701,10 +701,10 @@ public:
// version takes a HashKey and Unref()'s it when done. If we're a // version takes a HashKey and Unref()'s it when done. If we're a
// set, new_val has to be nil. If we aren't a set, index may be nil // set, new_val has to be nil. If we aren't a set, index may be nil
// in the second version. // in the second version.
int Assign(Val* index, IntrusivePtr<Val> new_val); bool Assign(Val* index, IntrusivePtr<Val> new_val);
int Assign(Val* index, Val* new_val); bool Assign(Val* index, Val* new_val);
int Assign(Val* index, HashKey* k, IntrusivePtr<Val> new_val); bool Assign(Val* index, HashKey* k, IntrusivePtr<Val> new_val);
int Assign(Val* index, HashKey* k, Val* new_val); bool Assign(Val* index, HashKey* k, Val* new_val);
IntrusivePtr<Val> SizeVal() const override; IntrusivePtr<Val> SizeVal() const override;
@ -713,10 +713,10 @@ public:
// Returns true if the addition typechecked, false if not. // Returns true if the addition typechecked, false if not.
// If is_first_init is true, then this is the *first* initialization // If is_first_init is true, then this is the *first* initialization
// (and so should be strictly adding new elements). // (and so should be strictly adding new elements).
int AddTo(Val* v, int is_first_init) const override; bool AddTo(Val* v, bool is_first_init) const override;
// Same but allows suppression of state operations. // Same but allows suppression of state operations.
int AddTo(Val* v, int is_first_init, bool propagate_ops) const; bool AddTo(Val* v, bool is_first_init, bool propagate_ops) const;
// Remove the entire contents. // Remove the entire contents.
void RemoveAll(); void RemoveAll();
@ -724,7 +724,7 @@ public:
// Remove the entire contents of the table from the given value. // Remove the entire contents of the table from the given value.
// which must also be a TableVal. // which must also be a TableVal.
// Returns true if the addition typechecked, false if not. // Returns true if the addition typechecked, false if not.
int RemoveFrom(Val* v) const override; bool RemoveFrom(Val* v) const override;
// Returns a new table that is the intersection of this // Returns a new table that is the intersection of this
// table and the given table. Intersection is just done // table and the given table. Intersection is just done
@ -744,7 +744,7 @@ public:
// Expands any lists in the index into multiple initializations. // Expands any lists in the index into multiple initializations.
// Returns true if the initializations typecheck, false if not. // Returns true if the initializations typecheck, false if not.
int ExpandAndInit(IntrusivePtr<Val> index, IntrusivePtr<Val> new_val); bool ExpandAndInit(IntrusivePtr<Val> index, IntrusivePtr<Val> new_val);
// Returns the element's value if it exists in the table, // Returns the element's value if it exists in the table,
// nil otherwise. Note, "index" is not const because we // nil otherwise. Note, "index" is not const because we
@ -836,8 +836,8 @@ protected:
void RebuildTable(ParseTimeTableState ptts); void RebuildTable(ParseTimeTableState ptts);
void CheckExpireAttr(attr_tag at); void CheckExpireAttr(attr_tag at);
int ExpandCompoundAndInit(val_list* vl, int k, IntrusivePtr<Val> new_val); bool ExpandCompoundAndInit(val_list* vl, int k, IntrusivePtr<Val> new_val);
int CheckAndAssign(Val* index, IntrusivePtr<Val> new_val); bool CheckAndAssign(Val* index, IntrusivePtr<Val> new_val);
// Calculates default value for index. Returns 0 if none. // Calculates default value for index. Returns 0 if none.
IntrusivePtr<Val> Default(Val* index); IntrusivePtr<Val> Default(Val* index);
@ -993,7 +993,7 @@ public:
// Add this value to the given value (if appropriate). // Add this value to the given value (if appropriate).
// Returns true if succcessful. // Returns true if succcessful.
int AddTo(Val* v, int is_first_init) const override; bool AddTo(Val* v, bool is_first_init) const override;
// Returns nil if no element was at that value. // Returns nil if no element was at that value.
// Lookup does NOT grow the vector to this size. // Lookup does NOT grow the vector to this size.
@ -1035,11 +1035,11 @@ protected:
// and returns nil, also Unref()'ing v. If is_init is true, then // and returns nil, also Unref()'ing v. If is_init is true, then
// the checking is done in the context of an initialization. // the checking is done in the context of an initialization.
extern IntrusivePtr<Val> check_and_promote(IntrusivePtr<Val> v, extern IntrusivePtr<Val> check_and_promote(IntrusivePtr<Val> v,
const BroType* t, int is_init, const BroType* t, bool is_init,
const Location* expr_location = nullptr); const Location* expr_location = nullptr);
extern int same_val(const Val* v1, const Val* v2); extern bool same_val(const Val* v1, const Val* v2);
extern int same_atomic_val(const Val* v1, const Val* v2); extern bool same_atomic_val(const Val* v1, const Val* v2);
extern bool is_atomic_val(const Val* v); extern bool is_atomic_val(const Val* v);
extern void describe_vals(const val_list* vals, ODesc* d, int offset=0); extern void describe_vals(const val_list* vals, ODesc* d, int offset=0);
extern void describe_vals(const std::vector<IntrusivePtr<Val>>& vals, extern void describe_vals(const std::vector<IntrusivePtr<Val>>& vals,

View file

@ -31,7 +31,7 @@ static IntrusivePtr<Val> init_val(Expr* init, const BroType* t,
static void make_var(ID* id, IntrusivePtr<BroType> t, init_class c, static void make_var(ID* id, IntrusivePtr<BroType> t, init_class c,
IntrusivePtr<Expr> init, attr_list* attr, decl_type dt, IntrusivePtr<Expr> init, attr_list* attr, decl_type dt,
int do_init) bool do_init)
{ {
if ( id->Type() ) if ( id->Type() )
{ {
@ -39,7 +39,7 @@ static void make_var(ID* id, IntrusivePtr<BroType> t, init_class c,
{ {
BroObj* redef_obj = init ? (BroObj*) init.get() : (BroObj*) t.get(); BroObj* redef_obj = init ? (BroObj*) init.get() : (BroObj*) t.get();
if ( dt != VAR_REDEF ) if ( dt != VAR_REDEF )
id->Warn("redefinition requires \"redef\"", redef_obj, 1); id->Warn("redefinition requires \"redef\"", redef_obj, true);
} }
else if ( dt != VAR_REDEF || init || ! attr ) else if ( dt != VAR_REDEF || init || ! attr )
@ -225,14 +225,14 @@ static void make_var(ID* id, IntrusivePtr<BroType> t, init_class c,
void add_global(ID* id, IntrusivePtr<BroType> t, init_class c, void add_global(ID* id, IntrusivePtr<BroType> t, init_class c,
IntrusivePtr<Expr> init, attr_list* attr, decl_type dt) IntrusivePtr<Expr> init, attr_list* attr, decl_type dt)
{ {
make_var(id, std::move(t), c, std::move(init), attr, dt, 1); make_var(id, std::move(t), c, std::move(init), attr, dt, true);
} }
IntrusivePtr<Stmt> add_local(IntrusivePtr<ID> id, IntrusivePtr<BroType> t, IntrusivePtr<Stmt> add_local(IntrusivePtr<ID> id, IntrusivePtr<BroType> t,
init_class c, IntrusivePtr<Expr> init, init_class c, IntrusivePtr<Expr> init,
attr_list* attr, decl_type dt) attr_list* attr, decl_type dt)
{ {
make_var(id.get(), std::move(t), c, init, attr, dt, 0); make_var(id.get(), std::move(t), c, init, attr, dt, false);
if ( init ) if ( init )
{ {
@ -264,10 +264,10 @@ extern IntrusivePtr<Expr> add_and_assign_local(IntrusivePtr<ID> id,
IntrusivePtr<Expr> init, IntrusivePtr<Expr> init,
IntrusivePtr<Val> val) IntrusivePtr<Val> val)
{ {
make_var(id.get(), 0, INIT_FULL, init, 0, VAR_REGULAR, 0); make_var(id.get(), nullptr, INIT_FULL, init, nullptr, VAR_REGULAR, false);
auto name_expr = make_intrusive<NameExpr>(std::move(id)); auto name_expr = make_intrusive<NameExpr>(std::move(id));
return make_intrusive<AssignExpr>(std::move(name_expr), std::move(init), return make_intrusive<AssignExpr>(std::move(name_expr), std::move(init),
0, std::move(val)); false, std::move(val));
} }
void add_type(ID* id, IntrusivePtr<BroType> t, attr_list* attr) void add_type(ID* id, IntrusivePtr<BroType> t, attr_list* attr)
@ -339,7 +339,7 @@ static bool has_attr(const attr_list* al, attr_tag tag)
} }
void begin_func(ID* id, const char* module_name, function_flavor flavor, void begin_func(ID* id, const char* module_name, function_flavor flavor,
int is_redef, IntrusivePtr<FuncType> t, attr_list* attrs) bool is_redef, IntrusivePtr<FuncType> t, attr_list* attrs)
{ {
if ( flavor == FUNC_FLAVOR_EVENT ) if ( flavor == FUNC_FLAVOR_EVENT )
{ {

View file

@ -32,7 +32,7 @@ extern IntrusivePtr<Expr> add_and_assign_local(IntrusivePtr<ID> id,
extern void add_type(ID* id, IntrusivePtr<BroType> t, attr_list* attr); extern void add_type(ID* id, IntrusivePtr<BroType> t, attr_list* attr);
extern void begin_func(ID* id, const char* module_name, function_flavor flavor, extern void begin_func(ID* id, const char* module_name, function_flavor flavor,
int is_redef, IntrusivePtr<FuncType> t, bool is_redef, IntrusivePtr<FuncType> t,
attr_list* attrs = nullptr); attr_list* attrs = nullptr);
extern void end_func(IntrusivePtr<Stmt> body); extern void end_func(IntrusivePtr<Stmt> body);

View file

@ -6,7 +6,7 @@
#include <unordered_map> #include <unordered_map>
struct WeirdState { struct WeirdState {
WeirdState() { count = 0; sampling_start_time = 0; } WeirdState() = default;
uint64_t count = 0; uint64_t count = 0;
double sampling_start_time = 0; double sampling_start_time = 0;
}; };

View file

@ -19,7 +19,7 @@ public:
virtual ~AnalyzerTimer(); virtual ~AnalyzerTimer();
void Dispatch(double t, int is_expire); void Dispatch(double t, bool is_expire) override;
protected: protected:
AnalyzerTimer() : analyzer(), timer(), do_expire() {} AnalyzerTimer() : analyzer(), timer(), do_expire() {}
@ -48,7 +48,7 @@ AnalyzerTimer::~AnalyzerTimer()
Unref(analyzer->Conn()); Unref(analyzer->Conn());
} }
void AnalyzerTimer::Dispatch(double t, int is_expire) void AnalyzerTimer::Dispatch(double t, bool is_expire)
{ {
if ( is_expire && ! do_expire ) if ( is_expire && ! do_expire )
return; return;
@ -725,7 +725,7 @@ void Analyzer::ProtocolViolation(const char* reason, const char* data, int len)
} }
void Analyzer::AddTimer(analyzer_timer_func timer, double t, void Analyzer::AddTimer(analyzer_timer_func timer, double t,
int do_expire, TimerType type) bool do_expire, TimerType type)
{ {
Timer* analyzer_timer = new Timer* analyzer_timer = new
AnalyzerTimer(this, timer, t, do_expire, type); AnalyzerTimer(this, timer, t, do_expire, type);
@ -752,7 +752,7 @@ void Analyzer::CancelTimers()
for ( auto timer : tmp ) for ( auto timer : tmp )
timer_mgr->Cancel(timer); timer_mgr->Cancel(timer);
timers_canceled = 1; timers_canceled = true;
timers.clear(); timers.clear();
} }
@ -929,7 +929,7 @@ void TransportLayerAnalyzer::PacketContents(const u_char* data, int len)
{ {
if ( packet_contents && len > 0 ) if ( packet_contents && len > 0 )
{ {
BroString* cbs = new BroString(data, len, 1); BroString* cbs = new BroString(data, len, true);
Val* contents = new StringVal(cbs); Val* contents = new StringVal(cbs);
Event(packet_contents, contents); Event(packet_contents, contents);
} }

View file

@ -648,7 +648,7 @@ protected:
* *
* @param type The timer's type. * @param type The timer's type.
*/ */
void AddTimer(analyzer_timer_func timer, double t, int do_expire, void AddTimer(analyzer_timer_func timer, double t, bool do_expire,
TimerType type); TimerType type);
/** /**

View file

@ -35,11 +35,11 @@ function set_current_conn_bytes_threshold%(cid: conn_id, threshold: count, is_or
%{ %{
analyzer::Analyzer* a = GetConnsizeAnalyzer(cid); analyzer::Analyzer* a = GetConnsizeAnalyzer(cid);
if ( ! a ) if ( ! a )
return val_mgr->GetBool(0); return val_mgr->GetFalse();
static_cast<analyzer::conn_size::ConnSize_Analyzer*>(a)->SetByteAndPacketThreshold(threshold, 1, is_orig); static_cast<analyzer::conn_size::ConnSize_Analyzer*>(a)->SetByteAndPacketThreshold(threshold, true, is_orig);
return val_mgr->GetBool(1); return val_mgr->GetTrue();
%} %}
## Sets a threshold for connection packets, overwtiting any potential old thresholds. ## Sets a threshold for connection packets, overwtiting any potential old thresholds.
@ -59,11 +59,11 @@ function set_current_conn_packets_threshold%(cid: conn_id, threshold: count, is_
%{ %{
analyzer::Analyzer* a = GetConnsizeAnalyzer(cid); analyzer::Analyzer* a = GetConnsizeAnalyzer(cid);
if ( ! a ) if ( ! a )
return val_mgr->GetBool(0); return val_mgr->GetFalse();
static_cast<analyzer::conn_size::ConnSize_Analyzer*>(a)->SetByteAndPacketThreshold(threshold, 0, is_orig); static_cast<analyzer::conn_size::ConnSize_Analyzer*>(a)->SetByteAndPacketThreshold(threshold, false, is_orig);
return val_mgr->GetBool(1); return val_mgr->GetTrue();
%} %}
## Sets the current duration threshold for connection, overwriting any potential old ## Sets the current duration threshold for connection, overwriting any potential old
@ -81,11 +81,11 @@ function set_current_conn_duration_threshold%(cid: conn_id, threshold: interval%
%{ %{
analyzer::Analyzer* a = GetConnsizeAnalyzer(cid); analyzer::Analyzer* a = GetConnsizeAnalyzer(cid);
if ( ! a ) if ( ! a )
return val_mgr->GetBool(0); return val_mgr->GetFalse();
static_cast<analyzer::conn_size::ConnSize_Analyzer*>(a)->SetDurationThreshold(threshold); static_cast<analyzer::conn_size::ConnSize_Analyzer*>(a)->SetDurationThreshold(threshold);
return val_mgr->GetBool(1); return val_mgr->GetTrue();
%} %}
# Gets the current byte threshold size for a connection. # Gets the current byte threshold size for a connection.
@ -105,7 +105,7 @@ function get_current_conn_bytes_threshold%(cid: conn_id, is_orig: bool%): count
if ( ! a ) if ( ! a )
return val_mgr->GetCount(0); return val_mgr->GetCount(0);
return val_mgr->GetCount(static_cast<analyzer::conn_size::ConnSize_Analyzer*>(a)->GetByteAndPacketThreshold(1, is_orig)); return val_mgr->GetCount(static_cast<analyzer::conn_size::ConnSize_Analyzer*>(a)->GetByteAndPacketThreshold(true, is_orig));
%} %}
## Gets the current packet threshold size for a connection. ## Gets the current packet threshold size for a connection.
@ -124,7 +124,7 @@ function get_current_conn_packets_threshold%(cid: conn_id, is_orig: bool%): coun
if ( ! a ) if ( ! a )
return val_mgr->GetCount(0); return val_mgr->GetCount(0);
return val_mgr->GetCount(static_cast<analyzer::conn_size::ConnSize_Analyzer*>(a)->GetByteAndPacketThreshold(0, is_orig)); return val_mgr->GetCount(static_cast<analyzer::conn_size::ConnSize_Analyzer*>(a)->GetByteAndPacketThreshold(false, is_orig));
%} %}
## Gets the current duration threshold size for a connection. ## Gets the current duration threshold size for a connection.

View file

@ -98,7 +98,7 @@ type DCE_RPC_Bind = record {
max_xmit_frag : uint16; max_xmit_frag : uint16;
max_recv_frag : uint16; max_recv_frag : uint16;
assoc_group_id : uint32; assoc_group_id : uint32;
context_list : ContextList(1, DCE_RPC_BIND); context_list : ContextList(true, DCE_RPC_BIND);
}; };
type DCE_RPC_Bind_Ack = record { type DCE_RPC_Bind_Ack = record {
@ -108,7 +108,7 @@ type DCE_RPC_Bind_Ack = record {
sec_addr_length : uint16; sec_addr_length : uint16;
sec_addr : bytestring &length=sec_addr_length; sec_addr : bytestring &length=sec_addr_length;
pad : padding align 4; pad : padding align 4;
contexts : ContextList(0, DCE_RPC_BIND_ACK); contexts : ContextList(false, DCE_RPC_BIND_ACK);
}; };
type DCE_RPC_Request(h: DCE_RPC_Header) = record { type DCE_RPC_Request(h: DCE_RPC_Header) = record {
@ -136,7 +136,7 @@ type DCE_RPC_AlterContext = record {
max_xmit_frag : uint16; max_xmit_frag : uint16;
max_recv_frag : uint16; max_recv_frag : uint16;
assoc_group_id : uint32; assoc_group_id : uint32;
context_list : ContextList(1, DCE_RPC_ALTER_CONTEXT); context_list : ContextList(true, DCE_RPC_ALTER_CONTEXT);
}; };
type DCE_RPC_AlterContext_Resp = record { type DCE_RPC_AlterContext_Resp = record {
@ -146,7 +146,7 @@ type DCE_RPC_AlterContext_Resp = record {
sec_addr_length : uint16; sec_addr_length : uint16;
sec_addr : bytestring &length=sec_addr_length; sec_addr : bytestring &length=sec_addr_length;
pad : padding align 4; pad : padding align 4;
contexts : ContextList(0, DCE_RPC_ALTER_CONTEXT_RESP); contexts : ContextList(false, DCE_RPC_ALTER_CONTEXT_RESP);
}; };
type DCE_RPC_Body(header: DCE_RPC_Header) = case header.PTYPE of { type DCE_RPC_Body(header: DCE_RPC_Header) = case header.PTYPE of {

View file

@ -409,12 +409,12 @@ void DNP3_TCP_Analyzer::DeliverStream(int len, const u_char* data, bool orig)
try try
{ {
if ( ! ProcessData(len, data, orig) ) if ( ! ProcessData(len, data, orig) )
SetSkip(1); SetSkip(true);
} }
catch ( const binpac::Exception& e ) catch ( const binpac::Exception& e )
{ {
SetSkip(1); SetSkip(true);
throw; throw;
} }
} }
@ -447,13 +447,12 @@ void DNP3_UDP_Analyzer::DeliverPacket(int len, const u_char* data, bool orig, ui
try try
{ {
if ( ! ProcessData(len, data, orig) ) if ( ! ProcessData(len, data, orig) )
SetSkip(1); SetSkip(true);
} }
catch ( const binpac::Exception& e ) catch ( const binpac::Exception& e )
{ {
SetSkip(1); SetSkip(true);
throw; throw;
} }
} }

View file

@ -25,14 +25,14 @@ DNS_Interpreter::DNS_Interpreter(analyzer::Analyzer* arg_analyzer)
first_message = true; first_message = true;
} }
int DNS_Interpreter::ParseMessage(const u_char* data, int len, int is_query) void DNS_Interpreter::ParseMessage(const u_char* data, int len, int is_query)
{ {
int hdr_len = sizeof(DNS_RawMsgHdr); int hdr_len = sizeof(DNS_RawMsgHdr);
if ( len < hdr_len ) if ( len < hdr_len )
{ {
analyzer->Weird("DNS_truncated_len_lt_hdr_len"); analyzer->Weird("DNS_truncated_len_lt_hdr_len");
return 0; return;
} }
DNS_MsgInfo msg((DNS_RawMsgHdr*) data, is_query); DNS_MsgInfo msg((DNS_RawMsgHdr*) data, is_query);
@ -62,7 +62,7 @@ int DNS_Interpreter::ParseMessage(const u_char* data, int len, int is_query)
analyzer->ProtocolViolation("DNS_Conn_count_too_large"); analyzer->ProtocolViolation("DNS_Conn_count_too_large");
analyzer->Weird("DNS_Conn_count_too_large"); analyzer->Weird("DNS_Conn_count_too_large");
EndMessage(&msg); EndMessage(&msg);
return 0; return;
} }
const u_char* msg_start = data; // needed for interpreting compression const u_char* msg_start = data; // needed for interpreting compression
@ -73,14 +73,14 @@ int DNS_Interpreter::ParseMessage(const u_char* data, int len, int is_query)
if ( ! ParseQuestions(&msg, data, len, msg_start) ) if ( ! ParseQuestions(&msg, data, len, msg_start) )
{ {
EndMessage(&msg); EndMessage(&msg);
return 0; return;
} }
if ( ! ParseAnswers(&msg, msg.ancount, DNS_ANSWER, if ( ! ParseAnswers(&msg, msg.ancount, DNS_ANSWER,
data, len, msg_start) ) data, len, msg_start) )
{ {
EndMessage(&msg); EndMessage(&msg);
return 0; return;
} }
analyzer->ProtocolConfirmation(); analyzer->ProtocolConfirmation();
@ -101,7 +101,7 @@ int DNS_Interpreter::ParseMessage(const u_char* data, int len, int is_query)
{ {
// No point doing further work parsing the message. // No point doing further work parsing the message.
EndMessage(&msg); EndMessage(&msg);
return 1; return;
} }
msg.skip_event = skip_auth; msg.skip_event = skip_auth;
@ -109,14 +109,14 @@ int DNS_Interpreter::ParseMessage(const u_char* data, int len, int is_query)
data, len, msg_start) ) data, len, msg_start) )
{ {
EndMessage(&msg); EndMessage(&msg);
return 0; return;
} }
if ( skip_addl ) if ( skip_addl )
{ {
// No point doing further work parsing the message. // No point doing further work parsing the message.
EndMessage(&msg); EndMessage(&msg);
return 1; return;
} }
msg.skip_event = skip_addl; msg.skip_event = skip_addl;
@ -124,25 +124,22 @@ int DNS_Interpreter::ParseMessage(const u_char* data, int len, int is_query)
data, len, msg_start) ) data, len, msg_start) )
{ {
EndMessage(&msg); EndMessage(&msg);
return 0; return;
} }
EndMessage(&msg); EndMessage(&msg);
return 1;
} }
int DNS_Interpreter::EndMessage(DNS_MsgInfo* msg) void DNS_Interpreter::EndMessage(DNS_MsgInfo* msg)
{ {
if ( dns_end ) if ( dns_end )
analyzer->EnqueueConnEvent(dns_end, analyzer->EnqueueConnEvent(dns_end,
IntrusivePtr{AdoptRef{}, analyzer->BuildConnVal()}, IntrusivePtr{AdoptRef{}, analyzer->BuildConnVal()},
IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()} IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}
); );
return 1;
} }
int DNS_Interpreter::ParseQuestions(DNS_MsgInfo* msg, bool DNS_Interpreter::ParseQuestions(DNS_MsgInfo* msg,
const u_char*& data, int& len, const u_char*& data, int& len,
const u_char* msg_start) const u_char* msg_start)
{ {
@ -153,7 +150,7 @@ int DNS_Interpreter::ParseQuestions(DNS_MsgInfo* msg,
return n == 0; return n == 0;
} }
int DNS_Interpreter::ParseAnswers(DNS_MsgInfo* msg, int n, DNS_AnswerType atype, bool DNS_Interpreter::ParseAnswers(DNS_MsgInfo* msg, int n, DNS_AnswerType atype,
const u_char*& data, int& len, const u_char*& data, int& len,
const u_char* msg_start) const u_char* msg_start)
{ {
@ -165,7 +162,7 @@ int DNS_Interpreter::ParseAnswers(DNS_MsgInfo* msg, int n, DNS_AnswerType atype,
return n == 0; return n == 0;
} }
int DNS_Interpreter::ParseQuestion(DNS_MsgInfo* msg, bool DNS_Interpreter::ParseQuestion(DNS_MsgInfo* msg,
const u_char*& data, int& len, const u_char*& data, int& len,
const u_char* msg_start) const u_char* msg_start)
{ {
@ -174,12 +171,12 @@ int DNS_Interpreter::ParseQuestion(DNS_MsgInfo* msg,
u_char* name_end = ExtractName(data, len, name, name_len, msg_start); u_char* name_end = ExtractName(data, len, name, name_len, msg_start);
if ( ! name_end ) if ( ! name_end )
return 0; return false;
if ( len < int(sizeof(short)) * 2 ) if ( len < int(sizeof(short)) * 2 )
{ {
analyzer->Weird("DNS_truncated_quest_too_short"); analyzer->Weird("DNS_truncated_quest_too_short");
return 0; return false;
} }
EventHandlerPtr dns_event = nullptr; EventHandlerPtr dns_event = nullptr;
@ -198,7 +195,7 @@ int DNS_Interpreter::ParseQuestion(DNS_MsgInfo* msg,
if ( dns_event && ! msg->skip_event ) if ( dns_event && ! msg->skip_event )
{ {
BroString* question_name = BroString* question_name =
new BroString(name, name_end - name, 1); new BroString(name, name_end - name, true);
SendReplyOrRejectEvent(msg, dns_event, data, len, question_name); SendReplyOrRejectEvent(msg, dns_event, data, len, question_name);
} }
else else
@ -208,10 +205,10 @@ int DNS_Interpreter::ParseQuestion(DNS_MsgInfo* msg,
(void) ExtractShort(data, len); (void) ExtractShort(data, len);
} }
return 1; return true;
} }
int DNS_Interpreter::ParseAnswer(DNS_MsgInfo* msg, bool DNS_Interpreter::ParseAnswer(DNS_MsgInfo* msg,
const u_char*& data, int& len, const u_char*& data, int& len,
const u_char* msg_start) const u_char* msg_start)
{ {
@ -221,19 +218,19 @@ int DNS_Interpreter::ParseAnswer(DNS_MsgInfo* msg,
u_char* name_end = ExtractName(data, len, name, name_len, msg_start); u_char* name_end = ExtractName(data, len, name, name_len, msg_start);
if ( ! name_end ) if ( ! name_end )
return 0; return false;
if ( len < int(sizeof(short)) * 2 ) if ( len < int(sizeof(short)) * 2 )
{ {
analyzer->Weird("DNS_truncated_ans_too_short"); analyzer->Weird("DNS_truncated_ans_too_short");
return 0; return false;
} }
// Note that the exact meaning of some of these fields will be // Note that the exact meaning of some of these fields will be
// re-interpreted by other, more adventurous RR types. // re-interpreted by other, more adventurous RR types.
Unref(msg->query_name); Unref(msg->query_name);
msg->query_name = new StringVal(new BroString(name, name_end - name, 1)); msg->query_name = new StringVal(new BroString(name, name_end - name, true));
msg->atype = RR_Type(ExtractShort(data, len)); msg->atype = RR_Type(ExtractShort(data, len));
msg->aclass = ExtractShort(data, len); msg->aclass = ExtractShort(data, len);
msg->ttl = ExtractLong(data, len); msg->ttl = ExtractLong(data, len);
@ -242,10 +239,10 @@ int DNS_Interpreter::ParseAnswer(DNS_MsgInfo* msg,
if ( rdlength > len ) if ( rdlength > len )
{ {
analyzer->Weird("DNS_truncated_RR_rdlength_lt_len"); analyzer->Weird("DNS_truncated_RR_rdlength_lt_len");
return 0; return false;
} }
int status; bool status;
switch ( msg->atype ) { switch ( msg->atype ) {
case TYPE_A: case TYPE_A:
status = ParseRR_A(msg, data, len, rdlength); status = ParseRR_A(msg, data, len, rdlength);
@ -301,7 +298,7 @@ int DNS_Interpreter::ParseAnswer(DNS_MsgInfo* msg,
// The SRV RFC reused the value that was already being // The SRV RFC reused the value that was already being
// used for this. // used for this.
// We aren't parsing this yet. // We aren't parsing this yet.
status = 1; status = true;
} }
else else
status = ParseRR_SRV(msg, data, len, rdlength, msg_start); status = ParseRR_SRV(msg, data, len, rdlength, msg_start);
@ -348,7 +345,7 @@ int DNS_Interpreter::ParseAnswer(DNS_MsgInfo* msg,
analyzer->Weird("DNS_RR_unknown_type", fmt("%d", msg->atype)); analyzer->Weird("DNS_RR_unknown_type", fmt("%d", msg->atype));
data += rdlength; data += rdlength;
len -= rdlength; len -= rdlength;
status = 1; status = true;
break; break;
} }
@ -384,12 +381,12 @@ u_char* DNS_Interpreter::ExtractName(const u_char*& data, int& len,
return name; return name;
} }
int DNS_Interpreter::ExtractLabel(const u_char*& data, int& len, bool DNS_Interpreter::ExtractLabel(const u_char*& data, int& len,
u_char*& name, int& name_len, u_char*& name, int& name_len,
const u_char* msg_start) const u_char* msg_start)
{ {
if ( len <= 0 ) if ( len <= 0 )
return 0; return false;
const u_char* orig_data = data; const u_char* orig_data = data;
int label_len = data[0]; int label_len = data[0];
@ -398,11 +395,11 @@ int DNS_Interpreter::ExtractLabel(const u_char*& data, int& len,
--len; --len;
if ( len <= 0 ) if ( len <= 0 )
return 0; return false;
if ( label_len == 0 ) if ( label_len == 0 )
// Found terminating label. // Found terminating label.
return 0; return false;
if ( (label_len & 0xc0) == 0xc0 ) if ( (label_len & 0xc0) == 0xc0 )
{ {
@ -424,7 +421,7 @@ int DNS_Interpreter::ExtractLabel(const u_char*& data, int& len,
// sometimes compression points to compression.) // sometimes compression points to compression.)
analyzer->Weird("DNS_label_forward_compress_offset"); analyzer->Weird("DNS_label_forward_compress_offset");
return 0; return false;
} }
// Recursively resolve name. // Recursively resolve name.
@ -437,7 +434,7 @@ int DNS_Interpreter::ExtractLabel(const u_char*& data, int& len,
name_len -= name_end - name; name_len -= name_end - name;
name = name_end; name = name_end;
return 0; return false;
} }
if ( label_len > len ) if ( label_len > len )
@ -445,7 +442,7 @@ int DNS_Interpreter::ExtractLabel(const u_char*& data, int& len,
analyzer->Weird("DNS_label_len_gt_pkt"); analyzer->Weird("DNS_label_len_gt_pkt");
data += len; // consume the rest of the packet data += len; // consume the rest of the packet
len = 0; len = 0;
return 0; return false;
} }
if ( label_len > 63 && if ( label_len > 63 &&
@ -453,13 +450,13 @@ int DNS_Interpreter::ExtractLabel(const u_char*& data, int& len,
ntohs(analyzer->Conn()->RespPort()) != 137 ) ntohs(analyzer->Conn()->RespPort()) != 137 )
{ {
analyzer->Weird("DNS_label_too_long"); analyzer->Weird("DNS_label_too_long");
return 0; return false;
} }
if ( label_len >= name_len ) if ( label_len >= name_len )
{ {
analyzer->Weird("DNS_label_len_gt_name_len"); analyzer->Weird("DNS_label_len_gt_name_len");
return 0; return false;
} }
memcpy(name, data, label_len); memcpy(name, data, label_len);
@ -471,7 +468,7 @@ int DNS_Interpreter::ExtractLabel(const u_char*& data, int& len,
data += label_len; data += label_len;
len -= label_len; len -= label_len;
return 1; return true;
} }
uint16_t DNS_Interpreter::ExtractShort(const u_char*& data, int& len) uint16_t DNS_Interpreter::ExtractShort(const u_char*& data, int& len)
@ -512,7 +509,7 @@ uint32_t DNS_Interpreter::ExtractLong(const u_char*& data, int& len)
return val; return val;
} }
int DNS_Interpreter::ParseRR_Name(DNS_MsgInfo* msg, bool DNS_Interpreter::ParseRR_Name(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start) const u_char* msg_start)
{ {
@ -523,7 +520,7 @@ int DNS_Interpreter::ParseRR_Name(DNS_MsgInfo* msg,
u_char* name_end = ExtractName(data, len, name, name_len, msg_start); u_char* name_end = ExtractName(data, len, name, name_len, msg_start);
if ( ! name_end ) if ( ! name_end )
return 0; return false;
if ( data - data_start != rdlength ) if ( data - data_start != rdlength )
{ {
@ -556,13 +553,13 @@ int DNS_Interpreter::ParseRR_Name(DNS_MsgInfo* msg,
IntrusivePtr{AdoptRef{}, analyzer->BuildConnVal()}, IntrusivePtr{AdoptRef{}, analyzer->BuildConnVal()},
IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()},
IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()}, IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()},
make_intrusive<StringVal>(new BroString(name, name_end - name, 1)) make_intrusive<StringVal>(new BroString(name, name_end - name, true))
); );
return 1; return true;
} }
int DNS_Interpreter::ParseRR_SOA(DNS_MsgInfo* msg, bool DNS_Interpreter::ParseRR_SOA(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start) const u_char* msg_start)
{ {
@ -573,17 +570,17 @@ int DNS_Interpreter::ParseRR_SOA(DNS_MsgInfo* msg,
u_char* mname_end = ExtractName(data, len, mname, mname_len, msg_start); u_char* mname_end = ExtractName(data, len, mname, mname_len, msg_start);
if ( ! mname_end ) if ( ! mname_end )
return 0; return false;
u_char rname[513]; u_char rname[513];
int rname_len = sizeof(rname) - 1; int rname_len = sizeof(rname) - 1;
u_char* rname_end = ExtractName(data, len, rname, rname_len, msg_start); u_char* rname_end = ExtractName(data, len, rname, rname_len, msg_start);
if ( ! rname_end ) if ( ! rname_end )
return 0; return false;
if ( len < 20 ) if ( len < 20 )
return 0; return false;
uint32_t serial = ExtractLong(data, len); uint32_t serial = ExtractLong(data, len);
uint32_t refresh = ExtractLong(data, len); uint32_t refresh = ExtractLong(data, len);
@ -597,8 +594,8 @@ int DNS_Interpreter::ParseRR_SOA(DNS_MsgInfo* msg,
if ( dns_SOA_reply && ! msg->skip_event ) if ( dns_SOA_reply && ! msg->skip_event )
{ {
auto r = make_intrusive<RecordVal>(dns_soa); auto r = make_intrusive<RecordVal>(dns_soa);
r->Assign(0, make_intrusive<StringVal>(new BroString(mname, mname_end - mname, 1))); r->Assign(0, make_intrusive<StringVal>(new BroString(mname, mname_end - mname, true)));
r->Assign(1, make_intrusive<StringVal>(new BroString(rname, rname_end - rname, 1))); r->Assign(1, make_intrusive<StringVal>(new BroString(rname, rname_end - rname, true)));
r->Assign(2, val_mgr->GetCount(serial)); r->Assign(2, val_mgr->GetCount(serial));
r->Assign(3, make_intrusive<IntervalVal>(double(refresh), Seconds)); r->Assign(3, make_intrusive<IntervalVal>(double(refresh), Seconds));
r->Assign(4, make_intrusive<IntervalVal>(double(retry), Seconds)); r->Assign(4, make_intrusive<IntervalVal>(double(retry), Seconds));
@ -613,10 +610,10 @@ int DNS_Interpreter::ParseRR_SOA(DNS_MsgInfo* msg,
); );
} }
return 1; return true;
} }
int DNS_Interpreter::ParseRR_MX(DNS_MsgInfo* msg, bool DNS_Interpreter::ParseRR_MX(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start) const u_char* msg_start)
{ {
@ -629,7 +626,7 @@ int DNS_Interpreter::ParseRR_MX(DNS_MsgInfo* msg,
u_char* name_end = ExtractName(data, len, name, name_len, msg_start); u_char* name_end = ExtractName(data, len, name, name_len, msg_start);
if ( ! name_end ) if ( ! name_end )
return 0; return false;
if ( data - data_start != rdlength ) if ( data - data_start != rdlength )
analyzer->Weird("DNS_RR_length_mismatch"); analyzer->Weird("DNS_RR_length_mismatch");
@ -639,23 +636,23 @@ int DNS_Interpreter::ParseRR_MX(DNS_MsgInfo* msg,
IntrusivePtr{AdoptRef{}, analyzer->BuildConnVal()}, IntrusivePtr{AdoptRef{}, analyzer->BuildConnVal()},
IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()},
IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()}, IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()},
make_intrusive<StringVal>(new BroString(name, name_end - name, 1)), make_intrusive<StringVal>(new BroString(name, name_end - name, true)),
IntrusivePtr{AdoptRef{}, val_mgr->GetCount(preference)} IntrusivePtr{AdoptRef{}, val_mgr->GetCount(preference)}
); );
return 1; return true;
} }
int DNS_Interpreter::ParseRR_NBS(DNS_MsgInfo* msg, bool DNS_Interpreter::ParseRR_NBS(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start) const u_char* msg_start)
{ {
data += rdlength; data += rdlength;
len -= rdlength; len -= rdlength;
return 1; return true;
} }
int DNS_Interpreter::ParseRR_SRV(DNS_MsgInfo* msg, bool DNS_Interpreter::ParseRR_SRV(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start) const u_char* msg_start)
{ {
@ -670,7 +667,7 @@ int DNS_Interpreter::ParseRR_SRV(DNS_MsgInfo* msg,
u_char* name_end = ExtractName(data, len, name, name_len, msg_start); u_char* name_end = ExtractName(data, len, name, name_len, msg_start);
if ( ! name_end ) if ( ! name_end )
return 0; return false;
if ( data - data_start != rdlength ) if ( data - data_start != rdlength )
analyzer->Weird("DNS_RR_length_mismatch"); analyzer->Weird("DNS_RR_length_mismatch");
@ -680,16 +677,16 @@ int DNS_Interpreter::ParseRR_SRV(DNS_MsgInfo* msg,
IntrusivePtr{AdoptRef{}, analyzer->BuildConnVal()}, IntrusivePtr{AdoptRef{}, analyzer->BuildConnVal()},
IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()},
IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()}, IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()},
make_intrusive<StringVal>(new BroString(name, name_end - name, 1)), make_intrusive<StringVal>(new BroString(name, name_end - name, true)),
IntrusivePtr{AdoptRef{}, val_mgr->GetCount(priority)}, IntrusivePtr{AdoptRef{}, val_mgr->GetCount(priority)},
IntrusivePtr{AdoptRef{}, val_mgr->GetCount(weight)}, IntrusivePtr{AdoptRef{}, val_mgr->GetCount(weight)},
IntrusivePtr{AdoptRef{}, val_mgr->GetCount(port)} IntrusivePtr{AdoptRef{}, val_mgr->GetCount(port)}
); );
return 1; return true;
} }
int DNS_Interpreter::ParseRR_EDNS(DNS_MsgInfo* msg, bool DNS_Interpreter::ParseRR_EDNS(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start) const u_char* msg_start)
{ {
@ -712,7 +709,7 @@ int DNS_Interpreter::ParseRR_EDNS(DNS_MsgInfo* msg,
len -= rdlength; len -= rdlength;
} }
return 1; return true;
} }
void DNS_Interpreter::ExtractOctets(const u_char*& data, int& len, void DNS_Interpreter::ExtractOctets(const u_char*& data, int& len,
@ -722,7 +719,7 @@ void DNS_Interpreter::ExtractOctets(const u_char*& data, int& len,
dlen = min(len, static_cast<int>(dlen)); dlen = min(len, static_cast<int>(dlen));
if ( p ) if ( p )
*p = new BroString(data, dlen, 0); *p = new BroString(data, dlen, false);
data += dlen; data += dlen;
len -= dlen; len -= dlen;
@ -732,14 +729,14 @@ BroString* DNS_Interpreter::ExtractStream(const u_char*& data, int& len, int l)
{ {
l = max(l, 0); l = max(l, 0);
int dlen = min(len, l); // Len in bytes of the algorithm use int dlen = min(len, l); // Len in bytes of the algorithm use
auto rval = new BroString(data, dlen, 0); auto rval = new BroString(data, dlen, false);
data += dlen; data += dlen;
len -= dlen; len -= dlen;
return rval; return rval;
} }
int DNS_Interpreter::ParseRR_TSIG(DNS_MsgInfo* msg, bool DNS_Interpreter::ParseRR_TSIG(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start) const u_char* msg_start)
{ {
@ -751,7 +748,7 @@ int DNS_Interpreter::ParseRR_TSIG(DNS_MsgInfo* msg,
ExtractName(data, len, alg_name, alg_name_len, msg_start); ExtractName(data, len, alg_name, alg_name_len, msg_start);
if ( ! alg_name_end ) if ( ! alg_name_end )
return 0; return false;
uint32_t sign_time_sec = ExtractLong(data, len); uint32_t sign_time_sec = ExtractLong(data, len);
unsigned int sign_time_msec = ExtractShort(data, len); unsigned int sign_time_msec = ExtractShort(data, len);
@ -766,7 +763,7 @@ int DNS_Interpreter::ParseRR_TSIG(DNS_MsgInfo* msg,
{ {
TSIG_DATA tsig; TSIG_DATA tsig;
tsig.alg_name = tsig.alg_name =
new BroString(alg_name, alg_name_end - alg_name, 1); new BroString(alg_name, alg_name_end - alg_name, true);
tsig.sig = request_MAC; tsig.sig = request_MAC;
tsig.time_s = sign_time_sec; tsig.time_s = sign_time_sec;
tsig.time_ms = sign_time_msec; tsig.time_ms = sign_time_msec;
@ -781,10 +778,10 @@ int DNS_Interpreter::ParseRR_TSIG(DNS_MsgInfo* msg,
); );
} }
return 1; return true;
} }
int DNS_Interpreter::ParseRR_RRSIG(DNS_MsgInfo* msg, bool DNS_Interpreter::ParseRR_RRSIG(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start) const u_char* msg_start)
{ {
@ -792,11 +789,11 @@ int DNS_Interpreter::ParseRR_RRSIG(DNS_MsgInfo* msg,
{ {
data += rdlength; data += rdlength;
len -= rdlength; len -= rdlength;
return 1; return true;
} }
if ( len < 18 ) if ( len < 18 )
return 0; return false;
unsigned int type_covered = ExtractShort(data, len); unsigned int type_covered = ExtractShort(data, len);
// split the two bytes for algo and labels extraction // split the two bytes for algo and labels extraction
@ -816,7 +813,7 @@ int DNS_Interpreter::ParseRR_RRSIG(DNS_MsgInfo* msg,
u_char* name_end = ExtractName(data, len, name, name_len, msg_start); u_char* name_end = ExtractName(data, len, name, name_len, msg_start);
if ( ! name_end ) if ( ! name_end )
return 0; return false;
int sig_len = rdlength - ((data - data_start) + 18); int sig_len = rdlength - ((data - data_start) + 18);
DNSSEC_Algo dsa = DNSSEC_Algo(algo); DNSSEC_Algo dsa = DNSSEC_Algo(algo);
@ -872,7 +869,7 @@ int DNS_Interpreter::ParseRR_RRSIG(DNS_MsgInfo* msg,
rrsig.sig_exp = sign_exp; rrsig.sig_exp = sign_exp;
rrsig.sig_incep = sign_incp; rrsig.sig_incep = sign_incp;
rrsig.key_tag = key_tag; rrsig.key_tag = key_tag;
rrsig.signer_name = new BroString(name, name_end - name, 1); rrsig.signer_name = new BroString(name, name_end - name, true);
rrsig.signature = sign; rrsig.signature = sign;
analyzer->EnqueueConnEvent(dns_RRSIG, analyzer->EnqueueConnEvent(dns_RRSIG,
@ -883,10 +880,10 @@ int DNS_Interpreter::ParseRR_RRSIG(DNS_MsgInfo* msg,
); );
} }
return 1; return true;
} }
int DNS_Interpreter::ParseRR_DNSKEY(DNS_MsgInfo* msg, bool DNS_Interpreter::ParseRR_DNSKEY(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start) const u_char* msg_start)
{ {
@ -894,11 +891,11 @@ int DNS_Interpreter::ParseRR_DNSKEY(DNS_MsgInfo* msg,
{ {
data += rdlength; data += rdlength;
len -= rdlength; len -= rdlength;
return 1; return true;
} }
if ( len < 4 ) if ( len < 4 )
return 0; return false;
auto dflags = ExtractShort(data, len); auto dflags = ExtractShort(data, len);
// split the two bytes for protocol and algorithm extraction // split the two bytes for protocol and algorithm extraction
@ -978,10 +975,10 @@ int DNS_Interpreter::ParseRR_DNSKEY(DNS_MsgInfo* msg,
); );
} }
return 1; return true;
} }
int DNS_Interpreter::ParseRR_NSEC(DNS_MsgInfo* msg, bool DNS_Interpreter::ParseRR_NSEC(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start) const u_char* msg_start)
{ {
@ -989,7 +986,7 @@ int DNS_Interpreter::ParseRR_NSEC(DNS_MsgInfo* msg,
{ {
data += rdlength; data += rdlength;
len -= rdlength; len -= rdlength;
return 1; return true;
} }
const u_char* data_start = data; const u_char* data_start = data;
@ -998,7 +995,7 @@ int DNS_Interpreter::ParseRR_NSEC(DNS_MsgInfo* msg,
u_char* name_end = ExtractName(data, len, name, name_len, msg_start); u_char* name_end = ExtractName(data, len, name, name_len, msg_start);
if ( ! name_end ) if ( ! name_end )
return 0; return false;
int typebitmaps_len = rdlength - (data - data_start); int typebitmaps_len = rdlength - (data - data_start);
@ -1026,14 +1023,14 @@ int DNS_Interpreter::ParseRR_NSEC(DNS_MsgInfo* msg,
IntrusivePtr{AdoptRef{}, analyzer->BuildConnVal()}, IntrusivePtr{AdoptRef{}, analyzer->BuildConnVal()},
IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()},
IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()}, IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()},
make_intrusive<StringVal>(new BroString(name, name_end - name, 1)), make_intrusive<StringVal>(new BroString(name, name_end - name, true)),
std::move(char_strings) std::move(char_strings)
); );
return 1; return true;
} }
int DNS_Interpreter::ParseRR_NSEC3(DNS_MsgInfo* msg, bool DNS_Interpreter::ParseRR_NSEC3(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start) const u_char* msg_start)
{ {
@ -1041,11 +1038,11 @@ int DNS_Interpreter::ParseRR_NSEC3(DNS_MsgInfo* msg,
{ {
data += rdlength; data += rdlength;
len -= rdlength; len -= rdlength;
return 1; return true;
} }
if ( len < 6 ) if ( len < 6 )
return 0; return false;
const u_char* data_start = data; const u_char* data_start = data;
uint32_t halgo_flags = ExtractShort(data, len); uint32_t halgo_flags = ExtractShort(data, len);
@ -1118,10 +1115,10 @@ int DNS_Interpreter::ParseRR_NSEC3(DNS_MsgInfo* msg,
else else
Unref(char_strings); Unref(char_strings);
return 1; return true;
} }
int DNS_Interpreter::ParseRR_DS(DNS_MsgInfo* msg, bool DNS_Interpreter::ParseRR_DS(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start) const u_char* msg_start)
{ {
@ -1129,11 +1126,11 @@ int DNS_Interpreter::ParseRR_DS(DNS_MsgInfo* msg,
{ {
data += rdlength; data += rdlength;
len -= rdlength; len -= rdlength;
return 1; return true;
} }
if ( len < 4 ) if ( len < 4 )
return 0; return false;
unsigned int ds_key_tag = ExtractShort(data, len); unsigned int ds_key_tag = ExtractShort(data, len);
// split the two bytes for algorithm and digest type extraction // split the two bytes for algorithm and digest type extraction
@ -1176,16 +1173,16 @@ int DNS_Interpreter::ParseRR_DS(DNS_MsgInfo* msg,
); );
} }
return 1; return true;
} }
int DNS_Interpreter::ParseRR_A(DNS_MsgInfo* msg, bool DNS_Interpreter::ParseRR_A(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength) const u_char*& data, int& len, int rdlength)
{ {
if ( rdlength != 4 ) if ( rdlength != 4 )
{ {
analyzer->Weird("DNS_RR_bad_length"); analyzer->Weird("DNS_RR_bad_length");
return 0; return false;
} }
uint32_t addr = ExtractLong(data, len); uint32_t addr = ExtractLong(data, len);
@ -1198,10 +1195,10 @@ int DNS_Interpreter::ParseRR_A(DNS_MsgInfo* msg,
make_intrusive<AddrVal>(htonl(addr)) make_intrusive<AddrVal>(htonl(addr))
); );
return 1; return true;
} }
int DNS_Interpreter::ParseRR_AAAA(DNS_MsgInfo* msg, bool DNS_Interpreter::ParseRR_AAAA(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength) const u_char*& data, int& len, int rdlength)
{ {
uint32_t addr[4]; uint32_t addr[4];
@ -1216,7 +1213,7 @@ int DNS_Interpreter::ParseRR_AAAA(DNS_MsgInfo* msg,
analyzer->Weird("DNS_AAAA_neg_length"); analyzer->Weird("DNS_AAAA_neg_length");
else else
analyzer->Weird("DNS_A6_neg_length"); analyzer->Weird("DNS_A6_neg_length");
return 0; return false;
} }
} }
@ -1234,25 +1231,25 @@ int DNS_Interpreter::ParseRR_AAAA(DNS_MsgInfo* msg,
make_intrusive<AddrVal>(addr) make_intrusive<AddrVal>(addr)
); );
return 1; return true;
} }
int DNS_Interpreter::ParseRR_WKS(DNS_MsgInfo* msg, bool DNS_Interpreter::ParseRR_WKS(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength) const u_char*& data, int& len, int rdlength)
{ {
data += rdlength; data += rdlength;
len -= rdlength; len -= rdlength;
return 1; return true;
} }
int DNS_Interpreter::ParseRR_HINFO(DNS_MsgInfo* msg, bool DNS_Interpreter::ParseRR_HINFO(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength) const u_char*& data, int& len, int rdlength)
{ {
data += rdlength; data += rdlength;
len -= rdlength; len -= rdlength;
return 1; return true;
} }
static StringVal* extract_char_string(analyzer::Analyzer* analyzer, static StringVal* extract_char_string(analyzer::Analyzer* analyzer,
@ -1283,7 +1280,7 @@ static StringVal* extract_char_string(analyzer::Analyzer* analyzer,
return rval; return rval;
} }
int DNS_Interpreter::ParseRR_TXT(DNS_MsgInfo* msg, bool DNS_Interpreter::ParseRR_TXT(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start) const u_char* msg_start)
{ {
@ -1291,7 +1288,7 @@ int DNS_Interpreter::ParseRR_TXT(DNS_MsgInfo* msg,
{ {
data += rdlength; data += rdlength;
len -= rdlength; len -= rdlength;
return 1; return true;
} }
auto char_strings = make_intrusive<VectorVal>(string_vec); auto char_strings = make_intrusive<VectorVal>(string_vec);
@ -1311,7 +1308,7 @@ int DNS_Interpreter::ParseRR_TXT(DNS_MsgInfo* msg,
return rdlength == 0; return rdlength == 0;
} }
int DNS_Interpreter::ParseRR_SPF(DNS_MsgInfo* msg, bool DNS_Interpreter::ParseRR_SPF(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start) const u_char* msg_start)
{ {
@ -1319,7 +1316,7 @@ int DNS_Interpreter::ParseRR_SPF(DNS_MsgInfo* msg,
{ {
data += rdlength; data += rdlength;
len -= rdlength; len -= rdlength;
return 1; return true;
} }
auto char_strings = make_intrusive<VectorVal>(string_vec); auto char_strings = make_intrusive<VectorVal>(string_vec);
@ -1339,7 +1336,7 @@ int DNS_Interpreter::ParseRR_SPF(DNS_MsgInfo* msg,
return rdlength == 0; return rdlength == 0;
} }
int DNS_Interpreter::ParseRR_CAA(DNS_MsgInfo* msg, bool DNS_Interpreter::ParseRR_CAA(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start) const u_char* msg_start)
{ {
@ -1347,7 +1344,7 @@ int DNS_Interpreter::ParseRR_CAA(DNS_MsgInfo* msg,
{ {
data += rdlength; data += rdlength;
len -= rdlength; len -= rdlength;
return 1; return true;
} }
unsigned int flags = ExtractShort(data, len); unsigned int flags = ExtractShort(data, len);
@ -1357,13 +1354,13 @@ int DNS_Interpreter::ParseRR_CAA(DNS_MsgInfo* msg,
if ( (int) tagLen >= rdlength ) if ( (int) tagLen >= rdlength )
{ {
analyzer->Weird("DNS_CAA_char_str_past_rdlen"); analyzer->Weird("DNS_CAA_char_str_past_rdlen");
return 0; return false;
} }
BroString* tag = new BroString(data, tagLen, 1); BroString* tag = new BroString(data, tagLen, true);
len -= tagLen; len -= tagLen;
data += tagLen; data += tagLen;
rdlength -= tagLen; rdlength -= tagLen;
BroString* value = new BroString(data, rdlength, 0); BroString* value = new BroString(data, rdlength, false);
len -= value->Len(); len -= value->Len();
data += value->Len(); data += value->Len();
@ -1703,7 +1700,6 @@ DNS_Analyzer::DNS_Analyzer(Connection* conn)
{ {
interp = new DNS_Interpreter(this); interp = new DNS_Interpreter(this);
contents_dns_orig = contents_dns_resp = 0; contents_dns_orig = contents_dns_resp = 0;
did_session_done = 0;
if ( Conn()->ConnTransport() == TRANSPORT_TCP ) if ( Conn()->ConnTransport() == TRANSPORT_TCP )
{ {
@ -1715,7 +1711,7 @@ DNS_Analyzer::DNS_Analyzer(Connection* conn)
else else
{ {
ADD_ANALYZER_TIMER(&DNS_Analyzer::ExpireTimer, ADD_ANALYZER_TIMER(&DNS_Analyzer::ExpireTimer,
network_time + dns_session_timeout, 1, network_time + dns_session_timeout, true,
TIMER_DNS_EXPIRE); TIMER_DNS_EXPIRE);
} }
} }
@ -1733,7 +1729,7 @@ void DNS_Analyzer::Done()
{ {
tcp::TCP_ApplicationAnalyzer::Done(); tcp::TCP_ApplicationAnalyzer::Done();
if ( Conn()->ConnTransport() == TRANSPORT_UDP && ! did_session_done ) if ( Conn()->ConnTransport() == TRANSPORT_UDP )
Event(udp_session_done); Event(udp_session_done);
else else
interp->Timeout(); interp->Timeout();
@ -1743,12 +1739,12 @@ void DNS_Analyzer::DeliverPacket(int len, const u_char* data, bool orig,
uint64_t seq, const IP_Hdr* ip, int caplen) uint64_t seq, const IP_Hdr* ip, int caplen)
{ {
tcp::TCP_ApplicationAnalyzer::DeliverPacket(len, data, orig, seq, ip, caplen); tcp::TCP_ApplicationAnalyzer::DeliverPacket(len, data, orig, seq, ip, caplen);
interp->ParseMessage(data, len, orig); interp->ParseMessage(data, len, orig ? 1 : 0);
} }
void DNS_Analyzer::ConnectionClosed(tcp::TCP_Endpoint* endpoint, tcp::TCP_Endpoint* peer, void DNS_Analyzer::ConnectionClosed(tcp::TCP_Endpoint* endpoint, tcp::TCP_Endpoint* peer,
int gen_event) bool gen_event)
{ {
tcp::TCP_ApplicationAnalyzer::ConnectionClosed(endpoint, peer, gen_event); tcp::TCP_ApplicationAnalyzer::ConnectionClosed(endpoint, peer, gen_event);
@ -1769,5 +1765,5 @@ void DNS_Analyzer::ExpireTimer(double t)
} }
else else
ADD_ANALYZER_TIMER(&DNS_Analyzer::ExpireTimer, ADD_ANALYZER_TIMER(&DNS_Analyzer::ExpireTimer,
t + dns_session_timeout, 1, TIMER_DNS_EXPIRE); t + dns_session_timeout, true, TIMER_DNS_EXPIRE);
} }

View file

@ -222,29 +222,29 @@ class DNS_Interpreter {
public: public:
explicit DNS_Interpreter(analyzer::Analyzer* analyzer); explicit DNS_Interpreter(analyzer::Analyzer* analyzer);
int ParseMessage(const u_char* data, int len, int is_query); void ParseMessage(const u_char* data, int len, int is_query);
void Timeout() { } void Timeout() { }
protected: protected:
int EndMessage(DNS_MsgInfo* msg); void EndMessage(DNS_MsgInfo* msg);
int ParseQuestions(DNS_MsgInfo* msg, bool ParseQuestions(DNS_MsgInfo* msg,
const u_char*& data, int& len, const u_char*& data, int& len,
const u_char* start); const u_char* start);
int ParseAnswers(DNS_MsgInfo* msg, int n, DNS_AnswerType answer_type, bool ParseAnswers(DNS_MsgInfo* msg, int n, DNS_AnswerType answer_type,
const u_char*& data, int& len, const u_char*& data, int& len,
const u_char* start); const u_char* start);
int ParseQuestion(DNS_MsgInfo* msg, bool ParseQuestion(DNS_MsgInfo* msg,
const u_char*& data, int& len, const u_char* start); const u_char*& data, int& len, const u_char* start);
int ParseAnswer(DNS_MsgInfo* msg, bool ParseAnswer(DNS_MsgInfo* msg,
const u_char*& data, int& len, const u_char* start); const u_char*& data, int& len, const u_char* start);
u_char* ExtractName(const u_char*& data, int& len, u_char* ExtractName(const u_char*& data, int& len,
u_char* label, int label_len, u_char* label, int label_len,
const u_char* msg_start); const u_char* msg_start);
int ExtractLabel(const u_char*& data, int& len, bool ExtractLabel(const u_char*& data, int& len,
u_char*& label, int& label_len, u_char*& label, int& label_len,
const u_char* msg_start); const u_char* msg_start);
@ -254,57 +254,57 @@ protected:
BroString* ExtractStream(const u_char*& data, int& len, int sig_len); BroString* ExtractStream(const u_char*& data, int& len, int sig_len);
int ParseRR_Name(DNS_MsgInfo* msg, bool ParseRR_Name(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start); const u_char* msg_start);
int ParseRR_SOA(DNS_MsgInfo* msg, bool ParseRR_SOA(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start); const u_char* msg_start);
int ParseRR_MX(DNS_MsgInfo* msg, bool ParseRR_MX(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start); const u_char* msg_start);
int ParseRR_NBS(DNS_MsgInfo* msg, bool ParseRR_NBS(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start); const u_char* msg_start);
int ParseRR_SRV(DNS_MsgInfo* msg, bool ParseRR_SRV(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start); const u_char* msg_start);
int ParseRR_EDNS(DNS_MsgInfo* msg, bool ParseRR_EDNS(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start); const u_char* msg_start);
int ParseRR_A(DNS_MsgInfo* msg, bool ParseRR_A(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength); const u_char*& data, int& len, int rdlength);
int ParseRR_AAAA(DNS_MsgInfo* msg, bool ParseRR_AAAA(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength); const u_char*& data, int& len, int rdlength);
int ParseRR_WKS(DNS_MsgInfo* msg, bool ParseRR_WKS(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength); const u_char*& data, int& len, int rdlength);
int ParseRR_HINFO(DNS_MsgInfo* msg, bool ParseRR_HINFO(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength); const u_char*& data, int& len, int rdlength);
int ParseRR_TXT(DNS_MsgInfo* msg, bool ParseRR_TXT(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start); const u_char* msg_start);
int ParseRR_SPF(DNS_MsgInfo* msg, bool ParseRR_SPF(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start); const u_char* msg_start);
int ParseRR_CAA(DNS_MsgInfo* msg, bool ParseRR_CAA(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start); const u_char* msg_start);
int ParseRR_TSIG(DNS_MsgInfo* msg, bool ParseRR_TSIG(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start); const u_char* msg_start);
int ParseRR_RRSIG(DNS_MsgInfo* msg, bool ParseRR_RRSIG(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start); const u_char* msg_start);
int ParseRR_DNSKEY(DNS_MsgInfo* msg, bool ParseRR_DNSKEY(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start); const u_char* msg_start);
int ParseRR_NSEC(DNS_MsgInfo* msg, bool ParseRR_NSEC(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start); const u_char* msg_start);
int ParseRR_NSEC3(DNS_MsgInfo* msg, bool ParseRR_NSEC3(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start); const u_char* msg_start);
int ParseRR_DS(DNS_MsgInfo* msg, bool ParseRR_DS(DNS_MsgInfo* msg,
const u_char*& data, int& len, int rdlength, const u_char*& data, int& len, int rdlength,
const u_char* msg_start); const u_char* msg_start);
void SendReplyOrRejectEvent(DNS_MsgInfo* msg, EventHandlerPtr event, void SendReplyOrRejectEvent(DNS_MsgInfo* msg, EventHandlerPtr event,
@ -357,7 +357,7 @@ public:
void Init() override; void Init() override;
void Done() override; void Done() override;
void ConnectionClosed(tcp::TCP_Endpoint* endpoint, void ConnectionClosed(tcp::TCP_Endpoint* endpoint,
tcp::TCP_Endpoint* peer, int gen_event) override; tcp::TCP_Endpoint* peer, bool gen_event) override;
void ExpireTimer(double t); void ExpireTimer(double t);
static analyzer::Analyzer* Instantiate(Connection* conn) static analyzer::Analyzer* Instantiate(Connection* conn)
@ -367,10 +367,6 @@ protected:
DNS_Interpreter* interp; DNS_Interpreter* interp;
Contents_DNS* contents_dns_orig; Contents_DNS* contents_dns_orig;
Contents_DNS* contents_dns_resp; Contents_DNS* contents_dns_resp;
int did_session_done;
}; };
// FIXME: Doesn't really fit into new analyzer structure. What to do?
int IsReuse(double t, const u_char* pkt);
} } // namespace analyzer::* } } // namespace analyzer::*

View file

@ -75,7 +75,7 @@ void Finger_Analyzer::DeliverStream(int length, const u_char* data, bool is_orig
); );
Conn()->Match(Rule::FINGER, (const u_char *) line, Conn()->Match(Rule::FINGER, (const u_char *) line,
end_of_line - line, true, true, 1, true); end_of_line - line, true, true, true, true);
did_deliver = 1; did_deliver = 1;
} }

View file

@ -111,7 +111,7 @@ void FTP_Analyzer::DeliverStream(int length, const u_char* data, bool orig)
if ( rule_matcher ) if ( rule_matcher )
Conn()->Match(Rule::FTP, (const u_char *) cmd, Conn()->Match(Rule::FTP, (const u_char *) cmd,
end_of_line - cmd, true, true, 1, true); end_of_line - cmd, true, true, true, true);
} }
else else
{ {

View file

@ -41,7 +41,7 @@ static Val* parse_port(const char* line)
{ {
r->Assign(0, make_intrusive<AddrVal>(uint32_t(0))); r->Assign(0, make_intrusive<AddrVal>(uint32_t(0)));
r->Assign(1, val_mgr->GetPort(0, TRANSPORT_TCP)); r->Assign(1, val_mgr->GetPort(0, TRANSPORT_TCP));
r->Assign(2, val_mgr->GetBool(0)); r->Assign(2, val_mgr->GetFalse());
} }
return r; return r;
@ -218,4 +218,3 @@ function fmt_ftp_port%(a: addr, p: port%): string
return val_mgr->GetEmptyString(); return val_mgr->GetEmptyString();
} }
%} %}

View file

@ -85,13 +85,13 @@ void Gnutella_Analyzer::Done()
} }
int Gnutella_Analyzer::NextLine(const u_char* data, int len) bool Gnutella_Analyzer::NextLine(const u_char* data, int len)
{ {
if ( ! ms ) if ( ! ms )
return 0; return false;
if ( Established() || ms->current_offset >= len ) if ( Established() || ms->current_offset >= len )
return 0; return false;
for ( ; ms->current_offset < len; ++ms->current_offset ) for ( ; ms->current_offset < len; ++ms->current_offset )
{ {
@ -102,20 +102,20 @@ int Gnutella_Analyzer::NextLine(const u_char* data, int len)
{ {
ms->got_CR = 0; ms->got_CR = 0;
++ms->current_offset; ++ms->current_offset;
return 1; return true;
} }
else else
ms->buffer += data[ms->current_offset]; ms->buffer += data[ms->current_offset];
} }
return 0; return false;
} }
int Gnutella_Analyzer::IsHTTP(string header) bool Gnutella_Analyzer::IsHTTP(string header)
{ {
if ( header.find(" HTTP/1.") == string::npos ) if ( header.find(" HTTP/1.") == string::npos )
return 0; return false;
if ( gnutella_http_notify ) if ( gnutella_http_notify )
EnqueueConnEvent(gnutella_http_notify, IntrusivePtr{AdoptRef{}, BuildConnVal()}); EnqueueConnEvent(gnutella_http_notify, IntrusivePtr{AdoptRef{}, BuildConnVal()});
@ -135,20 +135,20 @@ int Gnutella_Analyzer::IsHTTP(string header)
Parent()->RemoveChildAnalyzer(this); Parent()->RemoveChildAnalyzer(this);
} }
return 1; return true;
} }
int Gnutella_Analyzer::GnutellaOK(string header) bool Gnutella_Analyzer::GnutellaOK(string header)
{ {
if ( strncmp("GNUTELLA", header.data(), 8) ) if ( strncmp("GNUTELLA", header.data(), 8) )
return 0; return false;
int codepos = header.find(' ') + 1; int codepos = header.find(' ') + 1;
if ( ! strncmp("200", header.data() + codepos, 3) ) if ( ! strncmp("200", header.data() + codepos, 3) )
return 1; return true;
return 0; return false;
} }
@ -320,4 +320,3 @@ void Gnutella_Analyzer::DeliverStream(int len, const u_char* data, bool orig)
else if ( gnutella_binary_msg ) else if ( gnutella_binary_msg )
DeliverMessages(len, data, orig); DeliverMessages(len, data, orig);
} }

View file

@ -45,12 +45,12 @@ public:
{ return new Gnutella_Analyzer(conn); } { return new Gnutella_Analyzer(conn); }
private: private:
int NextLine(const u_char* data, int len); bool NextLine(const u_char* data, int len);
int GnutellaOK(string header); bool GnutellaOK(string header);
int IsHTTP(string header); bool IsHTTP(string header);
int Established() const { return state == (ORIG_OK | RESP_OK); } bool Established() const { return state == (ORIG_OK | RESP_OK); }
void DeliverLines(int len, const u_char* data, bool orig); void DeliverLines(int len, const u_char* data, bool orig);

View file

@ -106,7 +106,7 @@ Val* BuildEndUserAddr(const InformationElement* ie)
break; break;
default: default:
ev->Assign(3, make_intrusive<StringVal>( ev->Assign(3, make_intrusive<StringVal>(
new BroString((const u_char*) d, len, 0))); new BroString((const u_char*) d, len, false)));
break; break;
} }
} }
@ -117,7 +117,7 @@ Val* BuildEndUserAddr(const InformationElement* ie)
Val* BuildAccessPointName(const InformationElement* ie) Val* BuildAccessPointName(const InformationElement* ie)
{ {
BroString* bs = new BroString((const u_char*) ie->ap_name()->value().data(), BroString* bs = new BroString((const u_char*) ie->ap_name()->value().data(),
ie->ap_name()->value().length(), 0); ie->ap_name()->value().length(), false);
return new StringVal(bs); return new StringVal(bs);
} }
@ -125,7 +125,7 @@ Val* BuildProtoConfigOptions(const InformationElement* ie)
{ {
const u_char* d = (const u_char*) ie->proto_config_opts()->value().data(); const u_char* d = (const u_char*) ie->proto_config_opts()->value().data();
int len = ie->proto_config_opts()->value().length(); int len = ie->proto_config_opts()->value().length();
return new StringVal(new BroString(d, len, 0)); return new StringVal(new BroString(d, len, false));
} }
Val* BuildGSN_Addr(const InformationElement* ie) Val* BuildGSN_Addr(const InformationElement* ie)
@ -142,7 +142,7 @@ Val* BuildGSN_Addr(const InformationElement* ie)
ev->Assign(0, make_intrusive<AddrVal>( ev->Assign(0, make_intrusive<AddrVal>(
IPAddr(IPv6, (const uint32*) d, IPAddr::Network))); IPAddr(IPv6, (const uint32*) d, IPAddr::Network)));
else else
ev->Assign(1, make_intrusive<StringVal>(new BroString((const u_char*) d, len, 0))); ev->Assign(1, make_intrusive<StringVal>(new BroString((const u_char*) d, len, false)));
return ev; return ev;
} }
@ -151,7 +151,7 @@ Val* BuildMSISDN(const InformationElement* ie)
{ {
const u_char* d = (const u_char*) ie->msisdn()->value().data(); const u_char* d = (const u_char*) ie->msisdn()->value().data();
int len = ie->msisdn()->value().length(); int len = ie->msisdn()->value().length();
return new StringVal(new BroString(d, len, 0)); return new StringVal(new BroString(d, len, false));
} }
Val* BuildQoS_Profile(const InformationElement* ie) Val* BuildQoS_Profile(const InformationElement* ie)
@ -162,7 +162,7 @@ Val* BuildQoS_Profile(const InformationElement* ie)
int len = ie->qos_profile()->data().length(); int len = ie->qos_profile()->data().length();
ev->Assign(0, val_mgr->GetCount(ie->qos_profile()->alloc_retention_priority())); ev->Assign(0, val_mgr->GetCount(ie->qos_profile()->alloc_retention_priority()));
ev->Assign(1, make_intrusive<StringVal>(new BroString(d, len, 0))); ev->Assign(1, make_intrusive<StringVal>(new BroString(d, len, false)));
return ev; return ev;
} }
@ -171,21 +171,21 @@ Val* BuildTrafficFlowTemplate(const InformationElement* ie)
{ {
const uint8* d = ie->traffic_flow_template()->value().data(); const uint8* d = ie->traffic_flow_template()->value().data();
int len = ie->traffic_flow_template()->value().length(); int len = ie->traffic_flow_template()->value().length();
return new StringVal(new BroString((const u_char*) d, len, 0)); return new StringVal(new BroString((const u_char*) d, len, false));
} }
Val* BuildTriggerID(const InformationElement* ie) Val* BuildTriggerID(const InformationElement* ie)
{ {
const uint8* d = ie->trigger_id()->value().data(); const uint8* d = ie->trigger_id()->value().data();
int len = ie->trigger_id()->value().length(); int len = ie->trigger_id()->value().length();
return new StringVal(new BroString((const u_char*) d, len, 0)); return new StringVal(new BroString((const u_char*) d, len, false));
} }
Val* BuildOMC_ID(const InformationElement* ie) Val* BuildOMC_ID(const InformationElement* ie)
{ {
const uint8* d = ie->omc_id()->value().data(); const uint8* d = ie->omc_id()->value().data();
int len = ie->omc_id()->value().length(); int len = ie->omc_id()->value().length();
return new StringVal(new BroString((const u_char*) d, len, 0)); return new StringVal(new BroString((const u_char*) d, len, false));
} }
Val* BuildPrivateExt(const InformationElement* ie) Val* BuildPrivateExt(const InformationElement* ie)
@ -196,7 +196,7 @@ Val* BuildPrivateExt(const InformationElement* ie)
int len = ie->private_ext()->value().length(); int len = ie->private_ext()->value().length();
ev->Assign(0, val_mgr->GetCount(ie->private_ext()->id())); ev->Assign(0, val_mgr->GetCount(ie->private_ext()->id()));
ev->Assign(1, make_intrusive<StringVal>(new BroString((const u_char*) d, len, 0))); ev->Assign(1, make_intrusive<StringVal>(new BroString((const u_char*) d, len, false)));
return ev; return ev;
} }
@ -771,4 +771,3 @@ flow GTPv1_Flow(is_orig: bool)
}; };
refine typeattr GTPv1_Header += &let { proc_gtpv1 = $context.flow.process_gtpv1(this); }; refine typeattr GTPv1_Header += &let { proc_gtpv1 = $context.flow.process_gtpv1(this); };

View file

@ -78,7 +78,7 @@ void HTTP_Entity::EndOfData()
MIME_Entity::EndOfData(); MIME_Entity::EndOfData();
} }
void HTTP_Entity::Deliver(int len, const char* data, int trailing_CRLF) void HTTP_Entity::Deliver(int len, const char* data, bool trailing_CRLF)
{ {
if ( DEBUG_http ) if ( DEBUG_http )
{ {
@ -142,7 +142,7 @@ void HTTP_Entity::Deliver(int len, const char* data, int trailing_CRLF)
SetPlainDelivery(0); SetPlainDelivery(0);
chunked_transfer_state = EXPECT_CHUNK_DATA_CRLF; chunked_transfer_state = EXPECT_CHUNK_DATA_CRLF;
} }
DeliverBody(len, data, 0); DeliverBody(len, data, false);
break; break;
case EXPECT_CHUNK_DATA_CRLF: case EXPECT_CHUNK_DATA_CRLF:
@ -159,7 +159,7 @@ void HTTP_Entity::Deliver(int len, const char* data, int trailing_CRLF)
ASSERT(! trailing_CRLF); ASSERT(! trailing_CRLF);
ASSERT(len <= expect_data_length); ASSERT(len <= expect_data_length);
DeliverBody(len, data, 0); DeliverBody(len, data, false);
expect_data_length -= len; expect_data_length -= len;
if ( expect_data_length <= 0 ) if ( expect_data_length <= 0 )
@ -184,7 +184,7 @@ private:
HTTP_Entity* entity; HTTP_Entity* entity;
}; };
void HTTP_Entity::DeliverBody(int len, const char* data, int trailing_CRLF) void HTTP_Entity::DeliverBody(int len, const char* data, bool trailing_CRLF)
{ {
if ( encoding == GZIP || encoding == DEFLATE ) if ( encoding == GZIP || encoding == DEFLATE )
{ {
@ -207,7 +207,7 @@ void HTTP_Entity::DeliverBody(int len, const char* data, int trailing_CRLF)
DeliverBodyClear(len, data, trailing_CRLF); DeliverBodyClear(len, data, trailing_CRLF);
} }
void HTTP_Entity::DeliverBodyClear(int len, const char* data, int trailing_CRLF) void HTTP_Entity::DeliverBodyClear(int len, const char* data, bool trailing_CRLF)
{ {
bool new_data = (body_length == 0); bool new_data = (body_length == 0);
@ -233,7 +233,7 @@ void HTTP_Entity::DeliverBodyClear(int len, const char* data, int trailing_CRLF)
// Returns 1 if the undelivered bytes are completely within the body, // Returns 1 if the undelivered bytes are completely within the body,
// otherwise returns 0. // otherwise returns 0.
int HTTP_Entity::Undelivered(int64_t len) bool HTTP_Entity::Undelivered(int64_t len)
{ {
if ( DEBUG_http ) if ( DEBUG_http )
{ {
@ -244,7 +244,7 @@ int HTTP_Entity::Undelivered(int64_t len)
// Don't propogate an entity (file) gap if we're still in the headers, // Don't propogate an entity (file) gap if we're still in the headers,
// or the body length was declared to be zero. // or the body length was declared to be zero.
if ( (end_of_data && in_header) || body_length == 0 ) if ( (end_of_data && in_header) || body_length == 0 )
return 0; return false;
if ( is_partial_content ) if ( is_partial_content )
{ {
@ -273,10 +273,10 @@ int HTTP_Entity::Undelivered(int64_t len)
if ( expect_data_length == 0 ) if ( expect_data_length == 0 )
chunked_transfer_state = EXPECT_CHUNK_DATA_CRLF; chunked_transfer_state = EXPECT_CHUNK_DATA_CRLF;
return 1; return true;
} }
else else
return 0; return false;
} }
else if ( content_length >= 0 ) else if ( content_length >= 0 )
@ -291,14 +291,14 @@ int HTTP_Entity::Undelivered(int64_t len)
if ( expect_data_length <= 0 ) if ( expect_data_length <= 0 )
EndOfData(); EndOfData();
return 1; return true;
} }
else else
return 0; return false;
} }
return 0; return false;
} }
void HTTP_Entity::SubmitData(int len, const char* buf) void HTTP_Entity::SubmitData(int len, const char* buf)
@ -613,7 +613,7 @@ HTTP_Message::~HTTP_Message()
delete [] entity_data_buffer; delete [] entity_data_buffer;
} }
Val* HTTP_Message::BuildMessageStat(const int interrupted, const char* msg) Val* HTTP_Message::BuildMessageStat(bool interrupted, const char* msg)
{ {
RecordVal* stat = new RecordVal(http_message_stat); RecordVal* stat = new RecordVal(http_message_stat);
int field = 0; int field = 0;
@ -626,7 +626,7 @@ Val* HTTP_Message::BuildMessageStat(const int interrupted, const char* msg)
return stat; return stat;
} }
void HTTP_Message::Done(const int interrupted, const char* detail) void HTTP_Message::Done(bool interrupted, const char* detail)
{ {
if ( finished ) if ( finished )
return; return;
@ -658,7 +658,7 @@ void HTTP_Message::Done(const int interrupted, const char* detail)
MyHTTP_Analyzer()->HTTP_MessageDone(is_orig, this); MyHTTP_Analyzer()->HTTP_MessageDone(is_orig, this);
} }
int HTTP_Message::Undelivered(int64_t len) bool HTTP_Message::Undelivered(int64_t len)
{ {
HTTP_Entity* e = current_entity ? current_entity HTTP_Entity* e = current_entity ? current_entity
: static_cast<HTTP_Entity*>(top_level); : static_cast<HTTP_Entity*>(top_level);
@ -666,10 +666,10 @@ int HTTP_Message::Undelivered(int64_t len)
if ( e && e->Undelivered(len) ) if ( e && e->Undelivered(len) )
{ {
content_gap_length += len; content_gap_length += len;
return 1; return true;
} }
return 0; return false;
} }
void HTTP_Message::BeginEntity(mime::MIME_Entity* entity) void HTTP_Message::BeginEntity(mime::MIME_Entity* entity)
@ -766,17 +766,17 @@ void HTTP_Message::SubmitData(int len, const char* buf)
{ {
if ( http_entity_data ) if ( http_entity_data )
MyHTTP_Analyzer()->HTTP_EntityData(is_orig, MyHTTP_Analyzer()->HTTP_EntityData(is_orig,
new BroString(reinterpret_cast<const u_char*>(buf), len, 0)); new BroString(reinterpret_cast<const u_char*>(buf), len, false));
} }
int HTTP_Message::RequestBuffer(int* plen, char** pbuf) bool HTTP_Message::RequestBuffer(int* plen, char** pbuf)
{ {
if ( ! entity_data_buffer ) if ( ! entity_data_buffer )
entity_data_buffer = new char[http_entity_data_delivery_size]; entity_data_buffer = new char[http_entity_data_delivery_size];
*plen = http_entity_data_delivery_size; *plen = http_entity_data_delivery_size;
*pbuf = entity_data_buffer; *pbuf = entity_data_buffer;
return 1; return true;
} }
void HTTP_Message::SubmitAllData() void HTTP_Message::SubmitAllData()
@ -878,8 +878,8 @@ void HTTP_Analyzer::Done()
tcp::TCP_ApplicationAnalyzer::Done(); tcp::TCP_ApplicationAnalyzer::Done();
RequestMade(1, "message interrupted when connection done"); RequestMade(true, "message interrupted when connection done");
ReplyMade(1, "message interrupted when connection done"); ReplyMade(true, "message interrupted when connection done");
delete request_message; delete request_message;
request_message = 0; request_message = 0;
@ -933,14 +933,14 @@ void HTTP_Analyzer::DeliverStream(int len, const u_char* data, bool is_orig)
if ( is_orig ) if ( is_orig )
{ {
if ( request_message ) if ( request_message )
request_message->Deliver(len, line, 0); request_message->Deliver(len, line, false);
else else
Weird("unexpected_client_HTTP_data"); Weird("unexpected_client_HTTP_data");
} }
else else
{ {
if ( reply_message ) if ( reply_message )
reply_message->Deliver(len, line, 0); reply_message->Deliver(len, line, false);
else else
Weird("unexpected_server_HTTP_data"); Weird("unexpected_server_HTTP_data");
} }
@ -1004,7 +1004,7 @@ void HTTP_Analyzer::DeliverStream(int len, const u_char* data, bool is_orig)
break; break;
case EXPECT_REQUEST_MESSAGE: case EXPECT_REQUEST_MESSAGE:
request_message->Deliver(len, line, 1); request_message->Deliver(len, line, true);
break; break;
case EXPECT_REQUEST_TRAILER: case EXPECT_REQUEST_TRAILER:
@ -1051,7 +1051,7 @@ void HTTP_Analyzer::DeliverStream(int len, const u_char* data, bool is_orig)
break; break;
case EXPECT_REPLY_MESSAGE: case EXPECT_REPLY_MESSAGE:
reply_message->Deliver(len, line, 1); reply_message->Deliver(len, line, true);
if ( connect_request && len == 0 ) if ( connect_request && len == 0 )
{ {
@ -1118,16 +1118,15 @@ void HTTP_Analyzer::Undelivered(uint64_t seq, int len, bool is_orig)
// reply contains a body may depend on knowing the // reply contains a body may depend on knowing the
// request method // request method
RequestMade(1, "message interrupted by a content gap"); RequestMade(true, "message interrupted by a content gap");
ReplyMade(1, "message interrupted by a content gap"); ReplyMade(true, "message interrupted by a content gap");
content_line->SetSkipDeliveries(1); content_line->SetSkipDeliveries(true);
content_line->SetSkipDeliveries(1);
} }
else else
{ {
ReplyMade(1, "message interrupted by a content gap"); ReplyMade(true, "message interrupted by a content gap");
content_line->SetSkipDeliveries(1); content_line->SetSkipDeliveries(true);
} }
} }
@ -1138,34 +1137,34 @@ void HTTP_Analyzer::EndpointEOF(bool is_orig)
// DEBUG_MSG("%.6f eof\n", network_time); // DEBUG_MSG("%.6f eof\n", network_time);
if ( is_orig ) if ( is_orig )
RequestMade(0, "message ends as connection contents are completely delivered"); RequestMade(false, "message ends as connection contents are completely delivered");
else else
ReplyMade(0, "message ends as connection contents are completely delivered"); ReplyMade(false, "message ends as connection contents are completely delivered");
} }
void HTTP_Analyzer::ConnectionFinished(int half_finished) void HTTP_Analyzer::ConnectionFinished(bool half_finished)
{ {
tcp::TCP_ApplicationAnalyzer::ConnectionFinished(half_finished); tcp::TCP_ApplicationAnalyzer::ConnectionFinished(half_finished);
// DEBUG_MSG("%.6f connection finished\n", network_time); // DEBUG_MSG("%.6f connection finished\n", network_time);
RequestMade(1, "message ends as connection is finished"); RequestMade(true, "message ends as connection is finished");
ReplyMade(1, "message ends as connection is finished"); ReplyMade(true, "message ends as connection is finished");
} }
void HTTP_Analyzer::ConnectionReset() void HTTP_Analyzer::ConnectionReset()
{ {
tcp::TCP_ApplicationAnalyzer::ConnectionReset(); tcp::TCP_ApplicationAnalyzer::ConnectionReset();
RequestMade(1, "message interrupted by RST"); RequestMade(true, "message interrupted by RST");
ReplyMade(1, "message interrupted by RST"); ReplyMade(true, "message interrupted by RST");
} }
void HTTP_Analyzer::PacketWithRST() void HTTP_Analyzer::PacketWithRST()
{ {
tcp::TCP_ApplicationAnalyzer::PacketWithRST(); tcp::TCP_ApplicationAnalyzer::PacketWithRST();
RequestMade(1, "message interrupted by RST"); RequestMade(true, "message interrupted by RST");
ReplyMade(1, "message interrupted by RST"); ReplyMade(true, "message interrupted by RST");
} }
void HTTP_Analyzer::GenStats() void HTTP_Analyzer::GenStats()
@ -1278,7 +1277,7 @@ error:
return 0; return 0;
} }
int HTTP_Analyzer::ParseRequest(const char* line, const char* end_of_line) bool HTTP_Analyzer::ParseRequest(const char* line, const char* end_of_line)
{ {
const char* end_of_uri; const char* end_of_uri;
const char* version_start; const char* version_start;
@ -1335,7 +1334,7 @@ int HTTP_Analyzer::ParseRequest(const char* line, const char* end_of_line)
unescaped_URI = new StringVal(unescape_URI((const u_char*) line, unescaped_URI = new StringVal(unescape_URI((const u_char*) line,
(const u_char*) end_of_uri, this)); (const u_char*) end_of_uri, this));
return 1; return true;
} }
// Only recognize [0-9][.][0-9]. // Only recognize [0-9][.][0-9].
@ -1396,7 +1395,7 @@ StringVal* HTTP_Analyzer::TruncateURI(StringVal* uri)
u_char* s = new u_char[truncate_http_URI + 4]; u_char* s = new u_char[truncate_http_URI + 4];
memcpy(s, str->Bytes(), truncate_http_URI); memcpy(s, str->Bytes(), truncate_http_URI);
memcpy(s + truncate_http_URI, "...", 4); memcpy(s + truncate_http_URI, "...", 4);
return new StringVal(new BroString(1, s, truncate_http_URI+3)); return new StringVal(new BroString(true, s, truncate_http_URI+3));
} }
else else
{ {
@ -1444,7 +1443,7 @@ void HTTP_Analyzer::HTTP_Reply()
} }
} }
void HTTP_Analyzer::RequestMade(const int interrupted, const char* msg) void HTTP_Analyzer::RequestMade(bool interrupted, const char* msg)
{ {
if ( ! request_ongoing ) if ( ! request_ongoing )
return; return;
@ -1470,7 +1469,7 @@ void HTTP_Analyzer::RequestMade(const int interrupted, const char* msg)
request_state = EXPECT_REQUEST_LINE; request_state = EXPECT_REQUEST_LINE;
} }
void HTTP_Analyzer::ReplyMade(const int interrupted, const char* msg) void HTTP_Analyzer::ReplyMade(bool interrupted, const char* msg)
{ {
if ( ! reply_ongoing ) if ( ! reply_ongoing )
return; return;
@ -1527,7 +1526,7 @@ void HTTP_Analyzer::RequestClash(Val* /* clash_val */)
Weird("multiple_HTTP_request_elements"); Weird("multiple_HTTP_request_elements");
// Flush out old values. // Flush out old values.
RequestMade(1, "request clash"); RequestMade(true, "request clash");
} }
const BroString* HTTP_Analyzer::UnansweredRequestMethod() const BroString* HTTP_Analyzer::UnansweredRequestMethod()
@ -1626,7 +1625,7 @@ int HTTP_Analyzer::ExpectReplyMessageBody()
return HTTP_BODY_EXPECTED; return HTTP_BODY_EXPECTED;
} }
void HTTP_Analyzer::HTTP_Header(int is_orig, mime::MIME_Header* h) void HTTP_Analyzer::HTTP_Header(bool is_orig, mime::MIME_Header* h)
{ {
// To be "liberal", we only look at "keep-alive" on the client // To be "liberal", we only look at "keep-alive" on the client
// side, and if seen assume the connection to be persistent. // side, and if seen assume the connection to be persistent.
@ -1679,7 +1678,7 @@ void HTTP_Analyzer::HTTP_Header(int is_orig, mime::MIME_Header* h)
} }
} }
void HTTP_Analyzer::HTTP_EntityData(int is_orig, BroString* entity_data) void HTTP_Analyzer::HTTP_EntityData(bool is_orig, BroString* entity_data)
{ {
if ( http_entity_data ) if ( http_entity_data )
EnqueueConnEvent(http_entity_data, EnqueueConnEvent(http_entity_data,
@ -1693,12 +1692,12 @@ void HTTP_Analyzer::HTTP_EntityData(int is_orig, BroString* entity_data)
} }
// Calls request/reply done // Calls request/reply done
void HTTP_Analyzer::HTTP_MessageDone(int is_orig, HTTP_Message* /* message */) void HTTP_Analyzer::HTTP_MessageDone(bool is_orig, HTTP_Message* /* message */)
{ {
if ( is_orig ) if ( is_orig )
RequestMade(0, "message ends normally"); RequestMade(false, "message ends normally");
else else
ReplyMade(0, "message ends normally"); ReplyMade(false, "message ends normally");
} }
void HTTP_Analyzer::InitHTTPMessage(tcp::ContentLine_Analyzer* cl, HTTP_Message*& message, void HTTP_Analyzer::InitHTTPMessage(tcp::ContentLine_Analyzer* cl, HTTP_Message*& message,
@ -1717,7 +1716,7 @@ void HTTP_Analyzer::InitHTTPMessage(tcp::ContentLine_Analyzer* cl, HTTP_Message*
init_header_length); init_header_length);
} }
void HTTP_Analyzer::SkipEntityData(int is_orig) void HTTP_Analyzer::SkipEntityData(bool is_orig)
{ {
HTTP_Message* msg = is_orig ? request_message : reply_message; HTTP_Message* msg = is_orig ? request_message : reply_message;
@ -1725,14 +1724,14 @@ void HTTP_Analyzer::SkipEntityData(int is_orig)
msg->SkipEntityData(); msg->SkipEntityData();
} }
int analyzer::http::is_reserved_URI_char(unsigned char ch) bool analyzer::http::is_reserved_URI_char(unsigned char ch)
{ // see RFC 3986 (definition of URI) { // see RFC 3986 (definition of URI)
return strchr(":/?#[]@!$&'()*+,;=", ch) != 0; return strchr(":/?#[]@!$&'()*+,;=", ch) != 0;
} }
int analyzer::http::is_unreserved_URI_char(unsigned char ch) bool analyzer::http::is_unreserved_URI_char(unsigned char ch)
{ // see RFC 3986 (definition of URI) { // see RFC 3986 (definition of URI)
return isalnum(ch) || strchr("-_.!~*\'()", ch) != 0; return isalnum(ch) != 0 || strchr("-_.!~*\'()", ch) != 0;
} }
void analyzer::http::escape_URI_char(unsigned char ch, unsigned char*& p) void analyzer::http::escape_URI_char(unsigned char ch, unsigned char*& p)
@ -1838,5 +1837,5 @@ BroString* analyzer::http::unescape_URI(const u_char* line, const u_char* line_e
URI_p[0] = 0; URI_p[0] = 0;
return new BroString(1, decoded_URI, URI_p - decoded_URI); return new BroString(true, decoded_URI, URI_p - decoded_URI);
} }

View file

@ -38,8 +38,8 @@ public:
} }
void EndOfData() override; void EndOfData() override;
void Deliver(int len, const char* data, int trailing_CRLF) override; void Deliver(int len, const char* data, bool trailing_CRLF) override;
int Undelivered(int64_t len); bool Undelivered(int64_t len);
int64_t BodyLength() const { return body_length; } int64_t BodyLength() const { return body_length; }
int64_t HeaderLength() const { return header_length; } int64_t HeaderLength() const { return header_length; }
void SkipBody() { deliver_body = 0; } void SkipBody() { deliver_body = 0; }
@ -57,9 +57,9 @@ protected:
int expect_body; int expect_body;
int64_t body_length; int64_t body_length;
int64_t header_length; int64_t header_length;
int deliver_body;
enum { IDENTITY, GZIP, COMPRESS, DEFLATE } encoding; enum { IDENTITY, GZIP, COMPRESS, DEFLATE } encoding;
zip::ZIP_Analyzer* zip; zip::ZIP_Analyzer* zip;
bool deliver_body;
bool is_partial_content; bool is_partial_content;
uint64_t offset; uint64_t offset;
int64_t instance_length; // total length indicated by content-range int64_t instance_length; // total length indicated by content-range
@ -68,8 +68,8 @@ protected:
MIME_Entity* NewChildEntity() override { return new HTTP_Entity(http_message, this, 1); } MIME_Entity* NewChildEntity() override { return new HTTP_Entity(http_message, this, 1); }
void DeliverBody(int len, const char* data, int trailing_CRLF); void DeliverBody(int len, const char* data, bool trailing_CRLF);
void DeliverBodyClear(int len, const char* data, int trailing_CRLF); void DeliverBodyClear(int len, const char* data, bool trailing_CRLF);
void SubmitData(int len, const char* buf) override; void SubmitData(int len, const char* buf) override;
@ -103,17 +103,17 @@ public:
HTTP_Message(HTTP_Analyzer* analyzer, tcp::ContentLine_Analyzer* cl, HTTP_Message(HTTP_Analyzer* analyzer, tcp::ContentLine_Analyzer* cl,
bool is_orig, int expect_body, int64_t init_header_length); bool is_orig, int expect_body, int64_t init_header_length);
~HTTP_Message() override; ~HTTP_Message() override;
void Done(const int interrupted, const char* msg); void Done(bool interrupted, const char* msg);
void Done() override { Done(0, "message ends normally"); } void Done() override { Done(false, "message ends normally"); }
int Undelivered(int64_t len); bool Undelivered(int64_t len);
void BeginEntity(mime::MIME_Entity* /* entity */) override; void BeginEntity(mime::MIME_Entity* /* entity */) override;
void EndEntity(mime::MIME_Entity* entity) override; void EndEntity(mime::MIME_Entity* entity) override;
void SubmitHeader(mime::MIME_Header* h) override; void SubmitHeader(mime::MIME_Header* h) override;
void SubmitAllHeaders(mime::MIME_HeaderList& /* hlist */) override; void SubmitAllHeaders(mime::MIME_HeaderList& /* hlist */) override;
void SubmitData(int len, const char* buf) override; void SubmitData(int len, const char* buf) override;
int RequestBuffer(int* plen, char** pbuf) override; bool RequestBuffer(int* plen, char** pbuf) override;
void SubmitAllData(); void SubmitAllData();
void SubmitEvent(int event_type, const char* detail) override; void SubmitEvent(int event_type, const char* detail) override;
@ -145,7 +145,7 @@ protected:
HTTP_Entity* current_entity; HTTP_Entity* current_entity;
Val* BuildMessageStat(const int interrupted, const char* msg); Val* BuildMessageStat(bool interrupted, const char* msg);
}; };
class HTTP_Analyzer : public tcp::TCP_ApplicationAnalyzer { class HTTP_Analyzer : public tcp::TCP_ApplicationAnalyzer {
@ -153,15 +153,15 @@ public:
HTTP_Analyzer(Connection* conn); HTTP_Analyzer(Connection* conn);
~HTTP_Analyzer() override; ~HTTP_Analyzer() override;
void HTTP_Header(int is_orig, mime::MIME_Header* h); void HTTP_Header(bool is_orig, mime::MIME_Header* h);
void HTTP_EntityData(int is_orig, BroString* entity_data); void HTTP_EntityData(bool is_orig, BroString* entity_data);
void HTTP_MessageDone(int is_orig, HTTP_Message* message); void HTTP_MessageDone(bool is_orig, HTTP_Message* message);
void HTTP_Event(const char* category, const char* detail); void HTTP_Event(const char* category, const char* detail);
void HTTP_Event(const char* category, StringVal *detail); void HTTP_Event(const char* category, StringVal *detail);
void SkipEntityData(int is_orig); void SkipEntityData(bool is_orig);
int IsConnectionClose() { return connection_close; } bool IsConnectionClose() { return connection_close; }
int HTTP_ReplyCode() const { return reply_code; }; int HTTP_ReplyCode() const { return reply_code; };
// Overriden from Analyzer. // Overriden from Analyzer.
@ -171,7 +171,7 @@ public:
// Overriden from tcp::TCP_ApplicationAnalyzer // Overriden from tcp::TCP_ApplicationAnalyzer
void EndpointEOF(bool is_orig) override; void EndpointEOF(bool is_orig) override;
void ConnectionFinished(int half_finished) override; void ConnectionFinished(bool half_finished) override;
void ConnectionReset() override; void ConnectionReset() override;
void PacketWithRST() override; void PacketWithRST() override;
@ -219,18 +219,18 @@ protected:
const char* PrefixWordMatch(const char* line, const char* end_of_line, const char* PrefixWordMatch(const char* line, const char* end_of_line,
const char* prefix); const char* prefix);
int ParseRequest(const char* line, const char* end_of_line); bool ParseRequest(const char* line, const char* end_of_line);
HTTP_VersionNumber HTTP_Version(int len, const char* data); HTTP_VersionNumber HTTP_Version(int len, const char* data);
void SetVersion(HTTP_VersionNumber* version, HTTP_VersionNumber new_version); void SetVersion(HTTP_VersionNumber* version, HTTP_VersionNumber new_version);
int RequestExpected() const { return num_requests == 0 || keep_alive; } bool RequestExpected() const { return num_requests == 0 || keep_alive; }
void HTTP_Request(); void HTTP_Request();
void HTTP_Reply(); void HTTP_Reply();
void RequestMade(const int interrupted, const char* msg); void RequestMade(bool interrupted, const char* msg);
void ReplyMade(const int interrupted, const char* msg); void ReplyMade(bool interrupted, const char* msg);
void RequestClash(Val* clash_val); void RequestClash(Val* clash_val);
const BroString* UnansweredRequestMethod(); const BroString* UnansweredRequestMethod();
@ -279,8 +279,8 @@ protected:
HTTP_Message* reply_message; HTTP_Message* reply_message;
}; };
extern int is_reserved_URI_char(unsigned char ch); extern bool is_reserved_URI_char(unsigned char ch);
extern int is_unreserved_URI_char(unsigned char ch); extern bool is_unreserved_URI_char(unsigned char ch);
extern void escape_URI_char(unsigned char ch, unsigned char*& p); extern void escape_URI_char(unsigned char ch, unsigned char*& p);
extern BroString* unescape_URI(const u_char* line, const u_char* line_end, extern BroString* unescape_URI(const u_char* line, const u_char* line_end,
analyzer::Analyzer* analyzer); analyzer::Analyzer* analyzer);

View file

@ -209,7 +209,7 @@ void ICMP_Analyzer::ICMP_Sent(const struct icmp* icmpp, int len, int caplen,
if ( icmp_sent_payload ) if ( icmp_sent_payload )
{ {
BroString* payload = new BroString(data, min(len, caplen), 0); BroString* payload = new BroString(data, min(len, caplen), false);
EnqueueConnEvent(icmp_sent_payload, EnqueueConnEvent(icmp_sent_payload,
IntrusivePtr{AdoptRef{}, BuildConnVal()}, IntrusivePtr{AdoptRef{}, BuildConnVal()},
@ -424,7 +424,7 @@ RecordVal* ICMP_Analyzer::ExtractICMP6Context(int len, const u_char*& data)
iprec->Assign(3, val_mgr->GetCount(frag_offset)); iprec->Assign(3, val_mgr->GetCount(frag_offset));
iprec->Assign(4, val_mgr->GetBool(bad_hdr_len)); iprec->Assign(4, val_mgr->GetBool(bad_hdr_len));
// bad_checksum is always false since IPv6 layer doesn't have a checksum. // bad_checksum is always false since IPv6 layer doesn't have a checksum.
iprec->Assign(5, val_mgr->GetBool(0)); iprec->Assign(5, val_mgr->GetFalse());
iprec->Assign(6, val_mgr->GetBool(MF)); iprec->Assign(6, val_mgr->GetBool(MF));
iprec->Assign(7, val_mgr->GetBool(DF)); iprec->Assign(7, val_mgr->GetBool(DF));
@ -433,7 +433,7 @@ RecordVal* ICMP_Analyzer::ExtractICMP6Context(int len, const u_char*& data)
bool ICMP_Analyzer::IsReuse(double /* t */, const u_char* /* pkt */) bool ICMP_Analyzer::IsReuse(double /* t */, const u_char* /* pkt */)
{ {
return 0; return false;
} }
void ICMP_Analyzer::Describe(ODesc* d) const void ICMP_Analyzer::Describe(ODesc* d) const
@ -460,14 +460,14 @@ void ICMP_Analyzer::UpdateConnVal(RecordVal *conn_val)
RecordVal *orig_endp = conn_val->Lookup("orig")->AsRecordVal(); RecordVal *orig_endp = conn_val->Lookup("orig")->AsRecordVal();
RecordVal *resp_endp = conn_val->Lookup("resp")->AsRecordVal(); RecordVal *resp_endp = conn_val->Lookup("resp")->AsRecordVal();
UpdateEndpointVal(orig_endp, 1); UpdateEndpointVal(orig_endp, true);
UpdateEndpointVal(resp_endp, 0); UpdateEndpointVal(resp_endp, false);
// Call children's UpdateConnVal // Call children's UpdateConnVal
Analyzer::UpdateConnVal(conn_val); Analyzer::UpdateConnVal(conn_val);
} }
void ICMP_Analyzer::UpdateEndpointVal(RecordVal* endp, int is_orig) void ICMP_Analyzer::UpdateEndpointVal(RecordVal* endp, bool is_orig)
{ {
Conn()->EnableStatusUpdateTimer(); Conn()->EnableStatusUpdateTimer();
@ -512,7 +512,7 @@ void ICMP_Analyzer::Echo(double t, const struct icmp* icmpp, int len,
int iid = ntohs(icmpp->icmp_hun.ih_idseq.icd_id); int iid = ntohs(icmpp->icmp_hun.ih_idseq.icd_id);
int iseq = ntohs(icmpp->icmp_hun.ih_idseq.icd_seq); int iseq = ntohs(icmpp->icmp_hun.ih_idseq.icd_seq);
BroString* payload = new BroString(data, caplen, 0); BroString* payload = new BroString(data, caplen, false);
EnqueueConnEvent(f, EnqueueConnEvent(f,
IntrusivePtr{AdoptRef{}, BuildConnVal()}, IntrusivePtr{AdoptRef{}, BuildConnVal()},
@ -771,7 +771,7 @@ VectorVal* ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_char* data)
{ {
if ( caplen >= length ) if ( caplen >= length )
{ {
BroString* link_addr = new BroString(data, length, 0); BroString* link_addr = new BroString(data, length, false);
rv->Assign(2, make_intrusive<StringVal>(link_addr)); rv->Assign(2, make_intrusive<StringVal>(link_addr));
} }
else else
@ -841,8 +841,7 @@ VectorVal* ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_char* data)
if ( set_payload_field ) if ( set_payload_field )
{ {
BroString* payload = BroString* payload = new BroString(data, min((int)length, caplen), false);
new BroString(data, min((int)length, caplen), 0);
rv->Assign(6, make_intrusive<StringVal>(payload)); rv->Assign(6, make_intrusive<StringVal>(payload));
} }

View file

@ -84,7 +84,7 @@ protected:
RuleMatcherState matcher_state; RuleMatcherState matcher_state;
private: private:
void UpdateEndpointVal(RecordVal* endp, int is_orig); void UpdateEndpointVal(RecordVal* endp, bool is_orig);
}; };
// Returns the counterpart type to the given type (e.g., the counterpart // Returns the counterpart type to the given type (e.g., the counterpart

View file

@ -174,7 +174,7 @@ void Ident_Analyzer::DeliverStream(int length, const u_char* data, bool is_orig)
BroString* sys_type_s = BroString* sys_type_s =
new BroString((const u_char*) sys_type, new BroString((const u_char*) sys_type,
sys_end - sys_type + 1, 1); sys_end - sys_type + 1, true);
line = skip_whitespace(colon + 1, end_of_line); line = skip_whitespace(colon + 1, end_of_line);

View file

@ -40,7 +40,7 @@ Login_Analyzer::Login_Analyzer(const char* name, Connection* conn)
user_text_last = MAX_USER_TEXT - 1; user_text_last = MAX_USER_TEXT - 1;
num_user_text = 0; num_user_text = 0;
client_name = username = 0; client_name = username = 0;
saw_ploy = is_VMS = 0; saw_ploy = is_VMS = false;
if ( ! re_skip_authentication ) if ( ! re_skip_authentication )
{ {
@ -136,7 +136,7 @@ void Login_Analyzer::NewLine(bool orig, char* line)
else if ( ! saw_ploy && IsSuccessMsg(line) ) else if ( ! saw_ploy && IsSuccessMsg(line) )
{ {
LoginEvent(login_success, line, 1); LoginEvent(login_success, line, true);
state = LOGIN_STATE_LOGGED_IN; state = LOGIN_STATE_LOGGED_IN;
} }
} }
@ -192,7 +192,7 @@ void Login_Analyzer::AuthenticationDialog(bool orig, char* line)
Confused("no_login_prompt", line); Confused("no_login_prompt", line);
const char* prompt = IsLoginPrompt(line); const char* prompt = IsLoginPrompt(line);
int is_timeout = IsTimeout(line); bool is_timeout = IsTimeout(line);
if ( prompt && ! IsSuccessMsg(line) && ! is_timeout ) if ( prompt && ! IsSuccessMsg(line) && ! is_timeout )
{ {
is_VMS = strstr(line, "Username:") != 0; is_VMS = strstr(line, "Username:") != 0;
@ -255,9 +255,9 @@ void Login_Analyzer::AuthenticationDialog(bool orig, char* line)
if ( IsDirectLoginPrompt(line) ) if ( IsDirectLoginPrompt(line) )
{ {
LoginEvent(login_success, line, 1); LoginEvent(login_success, line, true);
state = LOGIN_STATE_LOGGED_IN; state = LOGIN_STATE_LOGGED_IN;
SetSkip(1); SetSkip(true);
return; return;
} }
} }
@ -293,7 +293,7 @@ void Login_Analyzer::AuthenticationDialog(bool orig, char* line)
EnqueueConnEvent(authentication_skipped, IntrusivePtr{AdoptRef{}, BuildConnVal()}); EnqueueConnEvent(authentication_skipped, IntrusivePtr{AdoptRef{}, BuildConnVal()});
state = LOGIN_STATE_SKIP; state = LOGIN_STATE_SKIP;
SetSkip(1); SetSkip(true);
} }
else if ( IsSuccessMsg(line) || else if ( IsSuccessMsg(line) ||
@ -359,13 +359,13 @@ void Login_Analyzer::EndpointEOF(bool orig)
if ( state == LOGIN_STATE_AUTHENTICATE && HaveTypeahead() ) if ( state == LOGIN_STATE_AUTHENTICATE && HaveTypeahead() )
{ {
LoginEvent(login_success, "<EOF>", 1); LoginEvent(login_success, "<EOF>", true);
state = LOGIN_STATE_LOGGED_IN; state = LOGIN_STATE_LOGGED_IN;
} }
} }
void Login_Analyzer::LoginEvent(EventHandlerPtr f, const char* line, void Login_Analyzer::LoginEvent(EventHandlerPtr f, const char* line,
int no_user_okay) bool no_user_okay)
{ {
if ( ! f ) if ( ! f )
return; return;
@ -484,20 +484,20 @@ void Login_Analyzer::ConfusionText(const char* line)
); );
} }
int Login_Analyzer::IsPloy(const char* line) bool Login_Analyzer::IsPloy(const char* line)
{ {
if ( IsLoginPrompt(line) || IsFailureMsg(line) || IsSuccessMsg(line) || if ( IsLoginPrompt(line) || IsFailureMsg(line) || IsSuccessMsg(line) ||
IsSkipAuthentication(line) ) IsSkipAuthentication(line) )
{ {
saw_ploy = 1; saw_ploy = true;
Confused("possible_login_ploy", line); Confused("possible_login_ploy", line);
return 1; return true;
} }
else else
return 0; return false;
} }
int Login_Analyzer::IsSkipAuthentication(const char* line) const bool Login_Analyzer::IsSkipAuthentication(const char* line) const
{ {
return re_skip_authentication->MatchAnywhere(line); return re_skip_authentication->MatchAnywhere(line);
} }
@ -512,28 +512,28 @@ const char* Login_Analyzer::IsLoginPrompt(const char* line) const
return &line[prompt_match]; return &line[prompt_match];
} }
int Login_Analyzer::IsDirectLoginPrompt(const char* line) const bool Login_Analyzer::IsDirectLoginPrompt(const char* line) const
{ {
return re_direct_login_prompts->MatchAnywhere(line); return re_direct_login_prompts->MatchAnywhere(line);
} }
int Login_Analyzer::IsFailureMsg(const char* line) const bool Login_Analyzer::IsFailureMsg(const char* line) const
{ {
return re_login_failure_msgs->MatchAnywhere(line) && return re_login_failure_msgs->MatchAnywhere(line) &&
! re_login_non_failure_msgs->MatchAnywhere(line); ! re_login_non_failure_msgs->MatchAnywhere(line);
} }
int Login_Analyzer::IsSuccessMsg(const char* line) const bool Login_Analyzer::IsSuccessMsg(const char* line) const
{ {
return re_login_success_msgs->MatchAnywhere(line); return re_login_success_msgs->MatchAnywhere(line);
} }
int Login_Analyzer::IsTimeout(const char* line) const bool Login_Analyzer::IsTimeout(const char* line) const
{ {
return re_login_timeouts->MatchAnywhere(line); return re_login_timeouts->MatchAnywhere(line);
} }
int Login_Analyzer::IsEmpty(const char* line) const bool Login_Analyzer::IsEmpty(const char* line) const
{ {
if ( ! line ) if ( ! line )
return true; return true;
@ -591,12 +591,12 @@ Val* Login_Analyzer::PopUserTextVal()
char* s = PopUserText(); char* s = PopUserText();
if ( s ) if ( s )
return new StringVal(new BroString(1, byte_vec(s), strlen(s))); return new StringVal(new BroString(true, byte_vec(s), strlen(s)));
else else
return val_mgr->GetEmptyString(); return val_mgr->GetEmptyString();
} }
int Login_Analyzer::MatchesTypeahead(const char* line) const bool Login_Analyzer::MatchesTypeahead(const char* line) const
{ {
for ( int i = user_text_first, n = 0; n < num_user_text; ++i, ++n ) for ( int i = user_text_first, n = 0; n < num_user_text; ++i, ++n )
{ {
@ -604,10 +604,10 @@ int Login_Analyzer::MatchesTypeahead(const char* line) const
i = 0; i = 0;
if ( streq(user_text[i], line) ) if ( streq(user_text[i], line) )
return 1; return true;
} }
return 0; return false;
} }
void Login_Analyzer::FlushEmptyTypeahead() void Login_Analyzer::FlushEmptyTypeahead()

View file

@ -38,28 +38,28 @@ protected:
void NewLine(bool orig, char* line); void NewLine(bool orig, char* line);
void AuthenticationDialog(bool orig, char* line); void AuthenticationDialog(bool orig, char* line);
void LoginEvent(EventHandlerPtr f, const char* line, int no_user_okay=0); void LoginEvent(EventHandlerPtr f, const char* line, bool no_user_okay=false);
const char* GetUsername(const char* line) const; const char* GetUsername(const char* line) const;
void LineEvent(EventHandlerPtr f, const char* line); void LineEvent(EventHandlerPtr f, const char* line);
void Confused(const char* msg, const char* addl); void Confused(const char* msg, const char* addl);
void ConfusionText(const char* line); void ConfusionText(const char* line);
int IsPloy(const char* line); bool IsPloy(const char* line);
int IsSkipAuthentication(const char* line) const; bool IsSkipAuthentication(const char* line) const;
const char* IsLoginPrompt(const char* line) const; // nil if not const char* IsLoginPrompt(const char* line) const; // nil if not
int IsDirectLoginPrompt(const char* line) const; bool IsDirectLoginPrompt(const char* line) const;
int IsFailureMsg(const char* line) const; bool IsFailureMsg(const char* line) const;
int IsSuccessMsg(const char* line) const; bool IsSuccessMsg(const char* line) const;
int IsTimeout(const char* line) const; bool IsTimeout(const char* line) const;
int IsEmpty(const char* line) const; bool IsEmpty(const char* line) const;
void AddUserText(const char* line); // complains on overflow void AddUserText(const char* line); // complains on overflow
char* PeekUserText(); // internal warning on underflow char* PeekUserText(); // internal warning on underflow
char* PopUserText(); // internal warning on underflow char* PopUserText(); // internal warning on underflow
Val* PopUserTextVal(); Val* PopUserTextVal();
int MatchesTypeahead(const char* line) const; bool MatchesTypeahead(const char* line) const;
int 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 // If we have more user text than this unprocessed, we complain about
@ -79,8 +79,8 @@ protected:
int login_prompt_line; int login_prompt_line;
int failure_line; int failure_line;
int is_VMS; bool is_VMS;
int saw_ploy; bool saw_ploy;
}; };
} } // namespace analyzer::* } } // namespace analyzer::*

View file

@ -58,7 +58,7 @@ void TelnetOption::RecvOption(unsigned int type)
peer->SetWill(); peer->SetWill();
if ( SaidDo() ) if ( SaidDo() )
peer->SetActive(1); peer->SetActive(true);
break; break;
case TELNET_OPT_WONT: case TELNET_OPT_WONT:
@ -68,7 +68,7 @@ void TelnetOption::RecvOption(unsigned int type)
peer->SetWont(); peer->SetWont();
if ( SaidDont() ) if ( SaidDont() )
peer->SetActive(0); peer->SetActive(false);
break; break;
case TELNET_OPT_DO: case TELNET_OPT_DO:
@ -78,7 +78,7 @@ void TelnetOption::RecvOption(unsigned int type)
peer->SetDo(); peer->SetDo();
if ( SaidWill() ) if ( SaidWill() )
SetActive(1); SetActive(true);
break; break;
case TELNET_OPT_DONT: case TELNET_OPT_DONT:
@ -88,7 +88,7 @@ void TelnetOption::RecvOption(unsigned int type)
peer->SetDont(); peer->SetDont();
if ( SaidWont() ) if ( SaidWont() )
SetActive(0); SetActive(false);
break; break;
default: default:
@ -102,7 +102,7 @@ void TelnetOption::RecvSubOption(u_char* /* data */, int /* len */)
{ {
} }
void TelnetOption::SetActive(int is_active) void TelnetOption::SetActive(bool is_active)
{ {
active = is_active; active = is_active;
} }
@ -366,7 +366,7 @@ char* TelnetEnvironmentOption::ExtractEnv(u_char*& data, int& len, int& code)
return env; return env;
} }
void TelnetBinaryOption::SetActive(int is_active) void TelnetBinaryOption::SetActive(bool is_active)
{ {
endp->SetBinaryMode(is_active); endp->SetBinaryMode(is_active);
active = is_active; active = is_active;
@ -381,10 +381,7 @@ void TelnetBinaryOption::InconsistentOption(unsigned int /* type */)
NVT_Analyzer::NVT_Analyzer(Connection* conn, bool orig) NVT_Analyzer::NVT_Analyzer(Connection* conn, bool orig)
: tcp::ContentLine_Analyzer("NVT", conn, orig), : tcp::ContentLine_Analyzer("NVT", conn, orig), options()
peer(), pending_IAC(), IAC_pos(), is_suboption(), last_was_IAC(),
binary_mode(), encrypting_mode(), authentication_has_been_accepted(),
auth_name(), options(), num_options()
{ {
} }
@ -443,13 +440,13 @@ TelnetOption* NVT_Analyzer::FindPeerOption(unsigned int code)
void NVT_Analyzer::AuthenticationAccepted() void NVT_Analyzer::AuthenticationAccepted()
{ {
authentication_has_been_accepted = 1; authentication_has_been_accepted = true;
Event(authentication_accepted, PeerAuthName()); Event(authentication_accepted, PeerAuthName());
} }
void NVT_Analyzer::AuthenticationRejected() void NVT_Analyzer::AuthenticationRejected()
{ {
authentication_has_been_accepted = 0; authentication_has_been_accepted = false;
Event(authentication_rejected, PeerAuthName()); Event(authentication_rejected, PeerAuthName());
} }
@ -464,7 +461,7 @@ void NVT_Analyzer::SetTerminal(const u_char* terminal, int len)
if ( login_terminal ) if ( login_terminal )
EnqueueConnEvent(login_terminal, EnqueueConnEvent(login_terminal,
IntrusivePtr{AdoptRef{}, BuildConnVal()}, IntrusivePtr{AdoptRef{}, BuildConnVal()},
make_intrusive<StringVal>(new BroString(terminal, len, 0)) make_intrusive<StringVal>(new BroString(terminal, len, false))
); );
} }
@ -554,9 +551,9 @@ void NVT_Analyzer::DoDeliver(int len, const u_char* data)
break; break;
case TELNET_IAC: case TELNET_IAC:
pending_IAC = 1; pending_IAC = true;
IAC_pos = offset; IAC_pos = offset;
is_suboption = 0; is_suboption = false;
buf[offset++] = c; buf[offset++] = c;
ScanOption(seq, len - 1, data + 1); ScanOption(seq, len - 1, data + 1);
return; return;
@ -590,14 +587,14 @@ void NVT_Analyzer::ScanOption(int seq, int len, const u_char* data)
{ {
// An escaped 255, throw away the second // An escaped 255, throw away the second
// instance and drop the IAC state. // instance and drop the IAC state.
pending_IAC = 0; pending_IAC = false;
last_char = code; last_char = code;
} }
else if ( code == TELNET_OPT_SB ) else if ( code == TELNET_OPT_SB )
{ {
is_suboption = 1; is_suboption = true;
last_was_IAC = 0; last_was_IAC = false;
if ( offset >= buf_len ) if ( offset >= buf_len )
InitBuffer(buf_len * 2); InitBuffer(buf_len * 2);
@ -607,7 +604,7 @@ void NVT_Analyzer::ScanOption(int seq, int len, const u_char* data)
else if ( IS_3_BYTE_OPTION(code) ) else if ( IS_3_BYTE_OPTION(code) )
{ {
is_suboption = 0; is_suboption = false;
if ( offset >= buf_len ) if ( offset >= buf_len )
InitBuffer(buf_len * 2); InitBuffer(buf_len * 2);
@ -622,7 +619,7 @@ void NVT_Analyzer::ScanOption(int seq, int len, const u_char* data)
// Throw it and the IAC away. // Throw it and the IAC away.
--offset; --offset;
pending_IAC = 0; pending_IAC = false;
} }
// Recurse to munch on the remainder. // Recurse to munch on the remainder.
@ -637,7 +634,7 @@ void NVT_Analyzer::ScanOption(int seq, int len, const u_char* data)
// Delete the option. // Delete the option.
offset -= 2; // code + IAC offset -= 2; // code + IAC
pending_IAC = 0; pending_IAC = false;
DeliverStream(len - 1, data + 1, IsOrig()); DeliverStream(len - 1, data + 1, IsOrig());
return; return;
@ -653,7 +650,7 @@ void NVT_Analyzer::ScanOption(int seq, int len, const u_char* data)
if ( last_was_IAC ) if ( last_was_IAC )
{ {
last_was_IAC = 0; last_was_IAC = false;
if ( code == TELNET_IAC ) if ( code == TELNET_IAC )
{ {
@ -676,14 +673,14 @@ void NVT_Analyzer::ScanOption(int seq, int len, const u_char* data)
// Delete suboption. // Delete suboption.
offset = IAC_pos; offset = IAC_pos;
pending_IAC = is_suboption = 0; pending_IAC = is_suboption = false;
if ( code == TELNET_OPT_SE ) if ( code == TELNET_OPT_SE )
DeliverStream(len - 1, data + 1, IsOrig()); DeliverStream(len - 1, data + 1, IsOrig());
else else
{ {
// Munch on the new (broken) option. // Munch on the new (broken) option.
pending_IAC = 1; pending_IAC = true;
IAC_pos = offset; IAC_pos = offset;
buf[offset++] = TELNET_IAC; buf[offset++] = TELNET_IAC;
DeliverStream(len, data, IsOrig()); DeliverStream(len, data, IsOrig());
@ -726,4 +723,3 @@ void NVT_Analyzer::BadOptionTermination(unsigned int /* code */)
{ {
Event(bad_option_termination); Event(bad_option_termination);
} }

View file

@ -28,12 +28,12 @@ public:
unsigned int Code() const { return code; } unsigned int Code() const { return code; }
int IsActive() const { return active; } bool IsActive() const { return active; }
int SaidWill() const { return flags & OPT_SAID_WILL; } bool SaidWill() const { return flags & OPT_SAID_WILL; }
int SaidWont() const { return flags & OPT_SAID_WONT; } bool SaidWont() const { return flags & OPT_SAID_WONT; }
int SaidDo() const { return flags & OPT_SAID_DO; } bool SaidDo() const { return flags & OPT_SAID_DO; }
int SaidDont() const { return flags & OPT_SAID_DONT; } bool SaidDont() const { return flags & OPT_SAID_DONT; }
void SetWill() { flags |= OPT_SAID_WILL; } void SetWill() { flags |= OPT_SAID_WILL; }
void SetWont() { flags |= OPT_SAID_WONT; } void SetWont() { flags |= OPT_SAID_WONT; }
@ -43,7 +43,7 @@ public:
void RecvOption(unsigned int type); void RecvOption(unsigned int type);
virtual void RecvSubOption(u_char* data, int len); virtual void RecvSubOption(u_char* data, int len);
virtual void SetActive(int is_active); virtual void SetActive(bool is_active);
const NVT_Analyzer* Endpoint() const { return endp; } const NVT_Analyzer* Endpoint() const { return endp; }
@ -116,7 +116,7 @@ public:
: TelnetOption(arg_endp, TELNET_OPTION_BINARY) : TelnetOption(arg_endp, TELNET_OPTION_BINARY)
{ } { }
void SetActive(int is_active) override; void SetActive(bool is_active) override;
protected: protected:
void InconsistentOption(unsigned int type) override; void InconsistentOption(unsigned int type) override;
@ -154,19 +154,20 @@ protected:
virtual void BadOptionTermination(unsigned int code); virtual void BadOptionTermination(unsigned int code);
const char* PeerAuthName() const; const char* PeerAuthName() const;
NVT_Analyzer* peer; NVT_Analyzer* peer = nullptr;
int pending_IAC; // true if we're working on an option/IAC int IAC_pos = 0; // where the IAC was seen
int IAC_pos; // where the IAC was seen bool pending_IAC = false; // true if we're working on an option/IAC
int is_suboption; // true if current option is suboption bool is_suboption = false; // true if current option is suboption
int last_was_IAC; // for scanning suboptions bool last_was_IAC = false; // for scanning suboptions
bool authentication_has_been_accepted = false; // if true, we accepted peer's authentication
int binary_mode, encrypting_mode; int binary_mode = 0;
int authentication_has_been_accepted; // if true, we accepted peer's authentication int encrypting_mode = 0;
char* auth_name; char* auth_name = nullptr;
TelnetOption* options[NUM_TELNET_OPTIONS]; TelnetOption* options[NUM_TELNET_OPTIONS];
int num_options; int num_options = 0;
}; };
} } // namespace analyzer::* } } // namespace analyzer::*

View file

@ -28,11 +28,11 @@ function get_login_state%(cid: conn_id%): count
%{ %{
Connection* c = sessions->FindConnection(cid); Connection* c = sessions->FindConnection(cid);
if ( ! c ) if ( ! c )
return val_mgr->GetBool(0); return val_mgr->GetFalse();
analyzer::Analyzer* la = c->FindAnalyzer("Login"); analyzer::Analyzer* la = c->FindAnalyzer("Login");
if ( ! la ) if ( ! la )
return val_mgr->GetBool(0); return val_mgr->GetFalse();
return val_mgr->GetCount(int(static_cast<analyzer::login::Login_Analyzer*>(la)->LoginState())); return val_mgr->GetCount(int(static_cast<analyzer::login::Login_Analyzer*>(la)->LoginState()));
%} %}
@ -52,12 +52,12 @@ function set_login_state%(cid: conn_id, new_state: count%): bool
%{ %{
Connection* c = sessions->FindConnection(cid); Connection* c = sessions->FindConnection(cid);
if ( ! c ) if ( ! c )
return val_mgr->GetBool(0); return val_mgr->GetFalse();
analyzer::Analyzer* la = c->FindAnalyzer("Login"); analyzer::Analyzer* la = c->FindAnalyzer("Login");
if ( ! la ) if ( ! la )
return val_mgr->GetBool(0); return val_mgr->GetFalse();
static_cast<analyzer::login::Login_Analyzer*>(la)->SetLoginState(analyzer::login::login_state(new_state)); static_cast<analyzer::login::Login_Analyzer*>(la)->SetLoginState(analyzer::login::login_state(new_state));
return val_mgr->GetBool(1); return val_mgr->GetTrue();
%} %}

View file

@ -98,12 +98,12 @@ static const char* MIMEContentEncodingName[] = {
0, 0,
}; };
int is_null_data_chunk(data_chunk_t b) bool is_null_data_chunk(data_chunk_t b)
{ {
return b.data == 0; return b.data == 0;
} }
int is_lws(char ch) bool is_lws(char ch)
{ {
return ch == 9 || ch == 32; return ch == 9 || ch == 32;
} }
@ -250,7 +250,7 @@ int MIME_get_field_name(int len, const char* data, data_chunk_t* name)
} }
// See RFC 2045, page 12. // See RFC 2045, page 12.
int MIME_is_tspecial (char ch, bool is_boundary = false) static bool MIME_is_tspecial (char ch, bool is_boundary = false)
{ {
if ( is_boundary ) if ( is_boundary )
return ch == '"'; return ch == '"';
@ -260,12 +260,12 @@ int MIME_is_tspecial (char ch, bool is_boundary = false)
ch == '/' || ch == '[' || ch == ']' || ch == '?' || ch == '='; ch == '/' || ch == '[' || ch == ']' || ch == '?' || ch == '=';
} }
int MIME_is_field_name_char (char ch) bool MIME_is_field_name_char (char ch)
{ {
return ch >= 33 && ch <= 126 && ch != ':'; return ch >= 33 && ch <= 126 && ch != ':';
} }
int MIME_is_token_char (char ch, bool is_boundary = false) static bool MIME_is_token_char (char ch, bool is_boundary = false)
{ {
return ch >= 33 && ch <= 126 && ! MIME_is_tspecial(ch, is_boundary); return ch >= 33 && ch <= 126 && ! MIME_is_tspecial(ch, is_boundary);
} }
@ -399,7 +399,7 @@ int MIME_get_value(int len, const char* data, BroString*& buf, bool is_boundary)
if ( end < 0 ) if ( end < 0 )
return -1; return -1;
buf = new BroString((const u_char*)str.data, str.length, 1); buf = new BroString((const u_char*)str.data, str.length, true);
return offset + end; return offset + end;
} }
} }
@ -427,7 +427,7 @@ BroString* MIME_decode_quoted_pairs(data_chunk_t buf)
dest[j++] = data[i]; dest[j++] = data[i];
dest[j] = 0; dest[j] = 0;
return new BroString(1, (byte_vec) dest, j); return new BroString(true, (byte_vec) dest, j);
} }
@ -448,12 +448,12 @@ MIME_Multiline::~MIME_Multiline()
void MIME_Multiline::append(int len, const char* data) void MIME_Multiline::append(int len, const char* data)
{ {
buffer.push_back(new BroString((const u_char*) data, len, 1)); buffer.push_back(new BroString((const u_char*) data, len, true));
} }
BroString* MIME_Multiline::get_concatenated_line() BroString* MIME_Multiline::get_concatenated_line()
{ {
if ( buffer.size() == 0 ) if ( buffer.empty() )
return 0; return 0;
delete line; delete line;
@ -593,7 +593,7 @@ MIME_Entity::~MIME_Entity()
delete base64_decoder; delete base64_decoder;
} }
void MIME_Entity::Deliver(int len, const char* data, int trailing_CRLF) void MIME_Entity::Deliver(int len, const char* data, bool trailing_CRLF)
{ {
if ( in_header ) if ( in_header )
{ {
@ -669,7 +669,7 @@ void MIME_Entity::EndOfData()
message->EndEntity (this); message->EndEntity (this);
} }
void MIME_Entity::NewDataLine(int len, const char* data, int trailing_CRLF) void MIME_Entity::NewDataLine(int len, const char* data, bool trailing_CRLF)
{ {
if ( content_type == CONTENT_TYPE_MULTIPART ) if ( content_type == CONTENT_TYPE_MULTIPART )
{ {
@ -786,7 +786,7 @@ void MIME_Entity::ParseMIMEHeader(MIME_Header* h)
} }
} }
int MIME_Entity::ParseContentTypeField(MIME_Header* h) bool MIME_Entity::ParseContentTypeField(MIME_Header* h)
{ {
data_chunk_t val = h->get_value(); data_chunk_t val = h->get_value();
int len = val.length; int len = val.length;
@ -799,7 +799,7 @@ int MIME_Entity::ParseContentTypeField(MIME_Header* h)
if ( offset < 0 ) if ( offset < 0 )
{ {
IllegalFormat("media type/subtype not found in content type"); IllegalFormat("media type/subtype not found in content type");
return 0; return false;
} }
data += offset; data += offset;
len -= offset; len -= offset;
@ -822,10 +822,10 @@ int MIME_Entity::ParseContentTypeField(MIME_Header* h)
content_subtype = CONTENT_SUBTYPE_OTHER; content_subtype = CONTENT_SUBTYPE_OTHER;
} }
return 1; return true;
} }
int MIME_Entity::ParseContentEncodingField(MIME_Header* h) bool MIME_Entity::ParseContentEncodingField(MIME_Header* h)
{ {
data_chunk_t enc; data_chunk_t enc;
@ -833,10 +833,10 @@ int MIME_Entity::ParseContentEncodingField(MIME_Header* h)
if ( is_null_data_chunk(enc) ) if ( is_null_data_chunk(enc) )
{ {
IllegalFormat("encoding type not found in content encoding"); IllegalFormat("encoding type not found in content encoding");
return 0; return false;
} }
content_encoding_str = new BroString((const u_char*)enc.data, enc.length, 1); content_encoding_str = new BroString((const u_char*)enc.data, enc.length, true);
ParseContentEncoding(enc); ParseContentEncoding(enc);
if ( need_to_parse_parameters ) if ( need_to_parse_parameters )
@ -846,14 +846,14 @@ int MIME_Entity::ParseContentEncodingField(MIME_Header* h)
ParseFieldParameters(val.length, val.data); ParseFieldParameters(val.length, val.data);
} }
return 1; return true;
} }
int MIME_Entity::ParseFieldParameters(int len, const char* data) bool MIME_Entity::ParseFieldParameters(int len, const char* data)
{ {
data_chunk_t attr; data_chunk_t attr;
while ( 1 ) while ( true )
{ {
int offset = MIME_skip_lws_comments(len, data); int offset = MIME_skip_lws_comments(len, data);
if ( offset < 0 || offset >= len || data[offset] != ';' ) if ( offset < 0 || offset >= len || data[offset] != ';' )
@ -867,7 +867,7 @@ int MIME_Entity::ParseFieldParameters(int len, const char* data)
if ( offset < 0 ) if ( offset < 0 )
{ {
IllegalFormat("attribute name not found in parameter specification"); IllegalFormat("attribute name not found in parameter specification");
return 0; return false;
} }
data += offset; data += offset;
@ -902,7 +902,7 @@ int MIME_Entity::ParseFieldParameters(int len, const char* data)
data_chunk_t vd = get_data_chunk(val); data_chunk_t vd = get_data_chunk(val);
multipart_boundary = new BroString((const u_char*)vd.data, multipart_boundary = new BroString((const u_char*)vd.data,
vd.length, 1); vd.length, true);
} }
else else
// token or quoted-string // token or quoted-string
@ -920,7 +920,7 @@ int MIME_Entity::ParseFieldParameters(int len, const char* data)
delete val; delete val;
} }
return 1; return true;
} }
void MIME_Entity::ParseContentType(data_chunk_t type, data_chunk_t sub_type) void MIME_Entity::ParseContentType(data_chunk_t type, data_chunk_t sub_type)
@ -1000,7 +1000,7 @@ int MIME_Entity::CheckBoundaryDelimiter(int len, const char* data)
// trailing_CRLF indicates whether an implicit CRLF sequence follows data // trailing_CRLF indicates whether an implicit CRLF sequence follows data
// (the CRLF sequence is not included in data). // (the CRLF sequence is not included in data).
void MIME_Entity::DecodeDataLine(int len, const char* data, int trailing_CRLF) void MIME_Entity::DecodeDataLine(int len, const char* data, bool trailing_CRLF)
{ {
if ( ! mime_submit_data ) if ( ! mime_submit_data )
return; return;
@ -1024,7 +1024,7 @@ void MIME_Entity::DecodeDataLine(int len, const char* data, int trailing_CRLF)
FlushData(); FlushData();
} }
void MIME_Entity::DecodeBinary(int len, const char* data, int trailing_CRLF) void MIME_Entity::DecodeBinary(int len, const char* data, bool trailing_CRLF)
{ {
if ( delay_adding_implicit_CRLF ) if ( delay_adding_implicit_CRLF )
{ {
@ -1175,17 +1175,17 @@ void MIME_Entity::FinishDecodeBase64()
base64_decoder = 0; base64_decoder = 0;
} }
int MIME_Entity::GetDataBuffer() bool MIME_Entity::GetDataBuffer()
{ {
int ret = message->RequestBuffer(&data_buf_length, &data_buf_data); int ret = message->RequestBuffer(&data_buf_length, &data_buf_data);
if ( ! ret || data_buf_length == 0 || data_buf_data == 0 ) if ( ! ret || data_buf_length == 0 || data_buf_data == 0 )
{ {
// reporter->InternalError("cannot get data buffer from MIME_Message", ""); // reporter->InternalError("cannot get data buffer from MIME_Message", "");
return 0; return false;
} }
data_buf_offset = 0; data_buf_offset = 0;
return 1; return true;
} }
void MIME_Entity::DataOctet(char ch) void MIME_Entity::DataOctet(char ch)
@ -1337,7 +1337,7 @@ MIME_Mail::MIME_Mail(analyzer::Analyzer* mail_analyzer, bool orig, int buf_size)
length = max_chunk_length; length = max_chunk_length;
buffer_start = data_start = 0; buffer_start = data_start = 0;
data_buffer = new BroString(1, new u_char[length+1], length); data_buffer = new BroString(true, new u_char[length+1], length);
if ( mime_content_hash ) if ( mime_content_hash )
{ {
@ -1368,7 +1368,7 @@ void MIME_Mail::Done()
analyzer->EnqueueConnEvent(mime_content_hash, analyzer->EnqueueConnEvent(mime_content_hash,
IntrusivePtr{AdoptRef{}, analyzer->BuildConnVal()}, IntrusivePtr{AdoptRef{}, analyzer->BuildConnVal()},
IntrusivePtr{AdoptRef{}, val_mgr->GetCount(content_hash_length)}, IntrusivePtr{AdoptRef{}, val_mgr->GetCount(content_hash_length)},
make_intrusive<StringVal>(new BroString(1, digest, 16)) make_intrusive<StringVal>(new BroString(true, digest, 16))
); );
} }
@ -1459,7 +1459,7 @@ void MIME_Mail::SubmitData(int len, const char* buf)
if ( mime_entity_data || mime_all_data ) if ( mime_entity_data || mime_all_data )
{ {
BroString* s = new BroString((const u_char*) buf, len, 0); BroString* s = new BroString((const u_char*) buf, len, false);
if ( mime_entity_data ) if ( mime_entity_data )
entity_content.push_back(s); entity_content.push_back(s);
@ -1487,7 +1487,7 @@ void MIME_Mail::SubmitData(int len, const char* buf)
buffer_start = (buf + len) - (char*)data_buffer->Bytes(); buffer_start = (buf + len) - (char*)data_buffer->Bytes();
} }
int MIME_Mail::RequestBuffer(int* plen, char** pbuf) bool MIME_Mail::RequestBuffer(int* plen, char** pbuf)
{ {
data_start = buffer_start - min_overlap_length; data_start = buffer_start - min_overlap_length;
if ( data_start < 0 ) if ( data_start < 0 )
@ -1509,7 +1509,7 @@ int MIME_Mail::RequestBuffer(int* plen, char** pbuf)
*plen = max_chunk_length - overlap; *plen = max_chunk_length - overlap;
*pbuf = (char*) data_buffer->Bytes() + buffer_start; *pbuf = (char*) data_buffer->Bytes() + buffer_start;
return 1; return true;
} }
void MIME_Mail::SubmitAllData() void MIME_Mail::SubmitAllData()

View file

@ -93,7 +93,7 @@ public:
MIME_Entity(MIME_Message* output_message, MIME_Entity* parent_entity); MIME_Entity(MIME_Message* output_message, MIME_Entity* parent_entity);
virtual ~MIME_Entity(); virtual ~MIME_Entity();
virtual void Deliver(int len, const char* data, int trailing_CRLF); virtual void Deliver(int len, const char* data, bool trailing_CRLF);
virtual void EndOfData(); virtual void EndOfData();
MIME_Entity* Parent() const { return parent; } MIME_Entity* Parent() const { return parent; }
@ -112,25 +112,25 @@ protected:
void ParseMIMEHeader(MIME_Header* h); void ParseMIMEHeader(MIME_Header* h);
int LookupMIMEHeaderName(data_chunk_t name); int LookupMIMEHeaderName(data_chunk_t name);
int ParseContentTypeField(MIME_Header* h); bool ParseContentTypeField(MIME_Header* h);
int ParseContentEncodingField(MIME_Header* h); bool ParseContentEncodingField(MIME_Header* h);
int ParseFieldParameters(int len, const char* data); bool ParseFieldParameters(int len, const char* data);
void ParseContentType(data_chunk_t type, data_chunk_t sub_type); void ParseContentType(data_chunk_t type, data_chunk_t sub_type);
void ParseContentEncoding(data_chunk_t encoding_mechanism); void ParseContentEncoding(data_chunk_t encoding_mechanism);
void BeginBody(); void BeginBody();
void NewDataLine(int len, const char* data, int trailing_CRLF); void NewDataLine(int len, const char* data, bool trailing_CRLF);
int CheckBoundaryDelimiter(int len, const char* data); int CheckBoundaryDelimiter(int len, const char* data);
void DecodeDataLine(int len, const char* data, int trailing_CRLF); void DecodeDataLine(int len, const char* data, bool trailing_CRLF);
void DecodeBinary(int len, const char* data, int trailing_CRLF); void DecodeBinary(int len, const char* data, bool trailing_CRLF);
void DecodeQuotedPrintable(int len, const char* data); void DecodeQuotedPrintable(int len, const char* data);
void DecodeBase64(int len, const char* data); void DecodeBase64(int len, const char* data);
void StartDecodeBase64(); void StartDecodeBase64();
void FinishDecodeBase64(); void FinishDecodeBase64();
int GetDataBuffer(); bool GetDataBuffer();
void DataOctet(char ch); void DataOctet(char ch);
void DataOctets(int len, const char* data); void DataOctets(int len, const char* data);
void FlushData(); void FlushData();
@ -189,7 +189,7 @@ public:
// not know its type yet (MIME_Entity / MIME_Mail / // not know its type yet (MIME_Entity / MIME_Mail /
// etc.). // etc.).
top_level = 0; top_level = 0;
finished = 0; finished = false;
analyzer = arg_analyzer; analyzer = arg_analyzer;
} }
@ -200,11 +200,11 @@ public:
"missing MIME_Message::Done() call"); "missing MIME_Message::Done() call");
} }
virtual void Done() { finished = 1; } virtual void Done() { finished = true; }
int Finished() const { return finished; } bool Finished() const { return finished; }
virtual void Deliver(int len, const char* data, int trailing_CRLF) virtual void Deliver(int len, const char* data, bool trailing_CRLF)
{ {
top_level->Deliver(len, data, trailing_CRLF); top_level->Deliver(len, data, trailing_CRLF);
} }
@ -217,14 +217,14 @@ public:
virtual void SubmitHeader(MIME_Header* h) = 0; virtual void SubmitHeader(MIME_Header* h) = 0;
virtual void SubmitAllHeaders(MIME_HeaderList& hlist) = 0; virtual void SubmitAllHeaders(MIME_HeaderList& hlist) = 0;
virtual void SubmitData(int len, const char* buf) = 0; virtual void SubmitData(int len, const char* buf) = 0;
virtual int RequestBuffer(int* plen, char** pbuf) = 0; virtual bool RequestBuffer(int* plen, char** pbuf) = 0;
virtual void SubmitEvent(int event_type, const char* detail) = 0; virtual void SubmitEvent(int event_type, const char* detail) = 0;
protected: protected:
analyzer::Analyzer* analyzer; analyzer::Analyzer* analyzer;
MIME_Entity* top_level; MIME_Entity* top_level;
int finished; bool finished;
RecordVal* BuildHeaderVal(MIME_Header* h); RecordVal* BuildHeaderVal(MIME_Header* h);
TableVal* BuildHeaderTable(MIME_HeaderList& hlist); TableVal* BuildHeaderTable(MIME_HeaderList& hlist);
@ -241,7 +241,7 @@ public:
void SubmitHeader(MIME_Header* h) override; void SubmitHeader(MIME_Header* h) override;
void SubmitAllHeaders(MIME_HeaderList& hlist) override; void SubmitAllHeaders(MIME_HeaderList& hlist) override;
void SubmitData(int len, const char* buf) override; void SubmitData(int len, const char* buf) override;
int RequestBuffer(int* plen, char** pbuf) override; bool RequestBuffer(int* plen, char** pbuf) override;
void SubmitAllData(); void SubmitAllData();
void SubmitEvent(int event_type, const char* detail) override; void SubmitEvent(int event_type, const char* detail) override;
void Undelivered(int len); void Undelivered(int len);
@ -265,14 +265,14 @@ protected:
}; };
extern int is_null_data_chunk(data_chunk_t b); extern bool is_null_data_chunk(data_chunk_t b);
extern StringVal* new_string_val(int length, const char* data); extern StringVal* new_string_val(int length, const char* data);
extern StringVal* new_string_val(const char* data, const char* end_of_data); extern StringVal* new_string_val(const char* data, const char* end_of_data);
extern StringVal* new_string_val(const data_chunk_t buf); extern StringVal* new_string_val(const data_chunk_t buf);
extern int fputs(data_chunk_t b, FILE* fp); extern int fputs(data_chunk_t b, FILE* fp);
extern bool istrequal(data_chunk_t s, const char* t); extern bool istrequal(data_chunk_t s, const char* t);
extern int is_lws(char ch); extern bool is_lws(char ch);
extern int MIME_is_field_name_char(char ch); extern bool MIME_is_field_name_char(char ch);
extern int MIME_count_leading_lws(int len, const char* data); extern int MIME_count_leading_lws(int len, const char* data);
extern int MIME_count_trailing_lws(int len, const char* data); extern int MIME_count_trailing_lws(int len, const char* data);
extern int MIME_skip_comments(int len, const char* data); extern int MIME_skip_comments(int len, const char* data);

View file

@ -30,7 +30,7 @@ NCP_Session::NCP_Session(analyzer::Analyzer* a)
req_func = 0; req_func = 0;
} }
void NCP_Session::Deliver(int is_orig, int len, const u_char* data) void NCP_Session::Deliver(bool is_orig, int len, const u_char* data)
{ {
try try
{ {
@ -258,4 +258,3 @@ NCP_Analyzer::~NCP_Analyzer()
{ {
delete session; delete session;
} }

View file

@ -31,9 +31,8 @@ namespace analyzer { namespace ncp {
class NCP_Session { class NCP_Session {
public: public:
explicit NCP_Session(analyzer::Analyzer* analyzer); explicit NCP_Session(analyzer::Analyzer* analyzer);
virtual ~NCP_Session() {}
virtual void Deliver(int is_orig, int len, const u_char* data); void Deliver(bool is_orig, int len, const u_char* data);
static bool any_ncp_event() static bool any_ncp_event()
{ {

View file

@ -55,8 +55,8 @@ NetbiosSSN_Interpreter::NetbiosSSN_Interpreter(Analyzer* arg_analyzer)
//smb_session = arg_smb_session; //smb_session = arg_smb_session;
} }
int NetbiosSSN_Interpreter::ParseMessage(unsigned int type, unsigned int flags, void NetbiosSSN_Interpreter::ParseMessage(unsigned int type, unsigned int flags,
const u_char* data, int len, int is_query) const u_char* data, int len, bool is_query)
{ {
if ( netbios_session_message ) if ( netbios_session_message )
analyzer->EnqueueConnEvent(netbios_session_message, analyzer->EnqueueConnEvent(netbios_session_message,
@ -68,54 +68,59 @@ int NetbiosSSN_Interpreter::ParseMessage(unsigned int type, unsigned int flags,
switch ( type ) { switch ( type ) {
case NETBIOS_SSN_MSG: case NETBIOS_SSN_MSG:
return ParseSessionMsg(data, len, is_query); ParseSessionMsg(data, len, is_query);
break;
case NETBIOS_SSN_REQ: case NETBIOS_SSN_REQ:
return ParseSessionReq(data, len, is_query); ParseSessionReq(data, len, is_query);
break;
case NETBIOS_SSN_POS_RESP: case NETBIOS_SSN_POS_RESP:
return ParseSessionPosResp(data, len, is_query); ParseSessionPosResp(data, len, is_query);
break;
case NETBIOS_SSN_NEG_RESP: case NETBIOS_SSN_NEG_RESP:
return ParseSessionNegResp(data, len, is_query); ParseSessionNegResp(data, len, is_query);
break;
case NETBIOS_SSN_RETARG_RESP: case NETBIOS_SSN_RETARG_RESP:
return ParseRetArgResp(data, len, is_query); ParseRetArgResp(data, len, is_query);
break;
case NETBIOS_SSN_KEEP_ALIVE: case NETBIOS_SSN_KEEP_ALIVE:
return ParseKeepAlive(data, len, is_query); ParseKeepAlive(data, len, is_query);
break;
case NETBIOS_DGM_DIRECT_UNIQUE: case NETBIOS_DGM_DIRECT_UNIQUE:
case NETBIOS_DGM_DIRECT_GROUP: case NETBIOS_DGM_DIRECT_GROUP:
case NETBIOS_DGM_BROADCAST: case NETBIOS_DGM_BROADCAST:
return ParseBroadcast(data, len, is_query); ParseBroadcast(data, len, is_query);
break;
case NETBIOS_DGM_ERROR: case NETBIOS_DGM_ERROR:
case NETBIOS_DGG_QUERY_REQ: case NETBIOS_DGG_QUERY_REQ:
case NETBIOS_DGM_POS_RESP: case NETBIOS_DGM_POS_RESP:
case NETBIOS_DGM_NEG_RESP: case NETBIOS_DGM_NEG_RESP:
return ParseDatagram(data, len, is_query); ParseDatagram(data, len, is_query);
break;
default: default:
analyzer->Weird("unknown_netbios_type", fmt("0x%x", type)); analyzer->Weird("unknown_netbios_type", fmt("0x%x", type));
return 1; break;
} }
} }
int NetbiosSSN_Interpreter::ParseDatagram(const u_char* data, int len, void NetbiosSSN_Interpreter::ParseDatagram(const u_char* data, int len,
int is_query) bool is_query)
{ {
//if ( smb_session ) //if ( smb_session )
// { // {
// smb_session->Deliver(is_query, len, data); // smb_session->Deliver(is_query, len, data);
// return 0;
// } // }
return 0;
} }
int NetbiosSSN_Interpreter::ParseBroadcast(const u_char* data, int len, void NetbiosSSN_Interpreter::ParseBroadcast(const u_char* data, int len,
int is_query) bool is_query)
{ {
// FIND THE NUL-TERMINATED NAME STRINGS HERE! // FIND THE NUL-TERMINATED NAME STRINGS HERE!
// Not sure what's in them, so we don't keep them currently. // Not sure what's in them, so we don't keep them currently.
@ -133,12 +138,10 @@ int NetbiosSSN_Interpreter::ParseBroadcast(const u_char* data, int len,
//if ( smb_session ) //if ( smb_session )
// smb_session->Deliver(is_query, len, data); // smb_session->Deliver(is_query, len, data);
return 0;
} }
int NetbiosSSN_Interpreter::ParseMessageTCP(const u_char* data, int len, void NetbiosSSN_Interpreter::ParseMessageTCP(const u_char* data, int len,
int is_query) bool is_query)
{ {
NetbiosSSN_RawMsgHdr hdr(data, len); NetbiosSSN_RawMsgHdr hdr(data, len);
@ -152,11 +155,11 @@ int NetbiosSSN_Interpreter::ParseMessageTCP(const u_char* data, int len,
len = hdr.length; len = hdr.length;
} }
return ParseMessage(hdr.type, hdr.flags, data, len, is_query); ParseMessage(hdr.type, hdr.flags, data, len, is_query);
} }
int NetbiosSSN_Interpreter::ParseMessageUDP(const u_char* data, int len, void NetbiosSSN_Interpreter::ParseMessageUDP(const u_char* data, int len,
int is_query) bool is_query)
{ {
NetbiosDGM_RawMsgHdr hdr(data, len); NetbiosDGM_RawMsgHdr hdr(data, len);
@ -172,19 +175,19 @@ int NetbiosSSN_Interpreter::ParseMessageUDP(const u_char* data, int len,
len = hdr.length; len = hdr.length;
} }
return ParseMessage(hdr.type, hdr.flags, data, len, is_query); ParseMessage(hdr.type, hdr.flags, data, len, is_query);
} }
int NetbiosSSN_Interpreter::ParseSessionMsg(const u_char* data, int len, void NetbiosSSN_Interpreter::ParseSessionMsg(const u_char* data, int len,
int is_query) bool is_query)
{ {
if ( len < 4 || strncmp((const char*) data, "\xffSMB", 4) ) if ( len < 4 || strncmp((const char*) data, "\xffSMB", 4) )
{ {
// This should be an event, too. // This should be an event, too.
analyzer->Weird("netbios_raw_session_msg"); analyzer->Weird("netbios_raw_session_msg");
Event(netbios_session_raw_message, data, len, is_query); Event(netbios_session_raw_message, data, len, is_query);
return 0; return;
} }
//if ( smb_session ) //if ( smb_session )
@ -197,14 +200,13 @@ int NetbiosSSN_Interpreter::ParseSessionMsg(const u_char* data, int len,
analyzer->Weird("no_smb_session_using_parsesambamsg"); analyzer->Weird("no_smb_session_using_parsesambamsg");
data += 4; data += 4;
len -= 4; len -= 4;
return ParseSambaMsg(data, len, is_query); ParseSambaMsg(data, len, is_query);
} }
} }
int NetbiosSSN_Interpreter::ParseSambaMsg(const u_char* data, int len, void NetbiosSSN_Interpreter::ParseSambaMsg(const u_char* data, int len,
int is_query) bool is_query)
{ {
return 0;
} }
int NetbiosSSN_Interpreter::ConvertName(const u_char* name, int name_len, int NetbiosSSN_Interpreter::ConvertName(const u_char* name, int name_len,
@ -246,8 +248,8 @@ int NetbiosSSN_Interpreter::ConvertName(const u_char* name, int name_len,
return 1; return 1;
} }
int NetbiosSSN_Interpreter::ParseSessionReq(const u_char* data, int len, void NetbiosSSN_Interpreter::ParseSessionReq(const u_char* data, int len,
int is_query) bool is_query)
{ {
if ( ! is_query ) if ( ! is_query )
analyzer->Weird("netbios_server_session_request"); analyzer->Weird("netbios_server_session_request");
@ -259,23 +261,19 @@ int NetbiosSSN_Interpreter::ParseSessionReq(const u_char* data, int len,
Event(netbios_session_request, xname, xlen); Event(netbios_session_request, xname, xlen);
delete [] xname; delete [] xname;
return 0;
} }
int NetbiosSSN_Interpreter::ParseSessionPosResp(const u_char* data, int len, void NetbiosSSN_Interpreter::ParseSessionPosResp(const u_char* data, int len,
int is_query) bool is_query)
{ {
if ( is_query ) if ( is_query )
analyzer->Weird("netbios_client_session_reply"); analyzer->Weird("netbios_client_session_reply");
Event(netbios_session_accepted, data, len); Event(netbios_session_accepted, data, len);
return 0;
} }
int NetbiosSSN_Interpreter::ParseSessionNegResp(const u_char* data, int len, void NetbiosSSN_Interpreter::ParseSessionNegResp(const u_char* data, int len,
int is_query) bool is_query)
{ {
if ( is_query ) if ( is_query )
analyzer->Weird("netbios_client_session_reply"); analyzer->Weird("netbios_client_session_reply");
@ -299,27 +297,21 @@ int NetbiosSSN_Interpreter::ParseSessionNegResp(const u_char* data, int len,
printf("Unspecified error 0x%X\n",ecode); printf("Unspecified error 0x%X\n",ecode);
break; break;
#endif #endif
return 0;
} }
int NetbiosSSN_Interpreter::ParseRetArgResp(const u_char* data, int len, void NetbiosSSN_Interpreter::ParseRetArgResp(const u_char* data, int len,
int is_query) bool is_query)
{ {
if ( is_query ) if ( is_query )
analyzer->Weird("netbios_client_session_reply"); analyzer->Weird("netbios_client_session_reply");
Event(netbios_session_ret_arg_resp, data, len); Event(netbios_session_ret_arg_resp, data, len);
return 0;
} }
int NetbiosSSN_Interpreter::ParseKeepAlive(const u_char* data, int len, void NetbiosSSN_Interpreter::ParseKeepAlive(const u_char* data, int len,
int is_query) bool is_query)
{ {
Event(netbios_session_keepalive, data, len); Event(netbios_session_keepalive, data, len);
return 0;
} }
void NetbiosSSN_Interpreter::Event(EventHandlerPtr event, const u_char* data, void NetbiosSSN_Interpreter::Event(EventHandlerPtr event, const u_char* data,
@ -332,12 +324,12 @@ void NetbiosSSN_Interpreter::Event(EventHandlerPtr event, const u_char* data,
analyzer->EnqueueConnEvent(event, analyzer->EnqueueConnEvent(event,
IntrusivePtr{AdoptRef{}, analyzer->BuildConnVal()}, IntrusivePtr{AdoptRef{}, analyzer->BuildConnVal()},
IntrusivePtr{AdoptRef{}, val_mgr->GetBool(is_orig)}, IntrusivePtr{AdoptRef{}, val_mgr->GetBool(is_orig)},
make_intrusive<StringVal>(new BroString(data, len, 0)) make_intrusive<StringVal>(new BroString(data, len, false))
); );
else else
analyzer->EnqueueConnEvent(event, analyzer->EnqueueConnEvent(event,
IntrusivePtr{AdoptRef{}, analyzer->BuildConnVal()}, IntrusivePtr{AdoptRef{}, analyzer->BuildConnVal()},
make_intrusive<StringVal>(new BroString(data, len, 0)) make_intrusive<StringVal>(new BroString(data, len, false))
); );
} }
@ -448,7 +440,7 @@ void Contents_NetbiosSSN::DeliverStream(int len, const u_char* data, bool orig)
// Haven't filled up the message buffer yet, no more to do. // Haven't filled up the message buffer yet, no more to do.
return; return;
(void) interp->ParseMessage(type, flags, msg_buf, msg_size, IsOrig()); interp->ParseMessage(type, flags, msg_buf, msg_size, IsOrig());
buf_n = 0; buf_n = 0;
state = NETBIOS_SSN_TYPE; state = NETBIOS_SSN_TYPE;
@ -476,7 +468,7 @@ NetbiosSSN_Analyzer::NetbiosSSN_Analyzer(Connection* conn)
else else
{ {
ADD_ANALYZER_TIMER(&NetbiosSSN_Analyzer::ExpireTimer, ADD_ANALYZER_TIMER(&NetbiosSSN_Analyzer::ExpireTimer,
network_time + netbios_ssn_session_timeout, 1, network_time + netbios_ssn_session_timeout, true,
TIMER_NB_EXPIRE); TIMER_NB_EXPIRE);
} }
} }
@ -506,7 +498,7 @@ void NetbiosSSN_Analyzer::EndpointEOF(bool orig)
} }
void NetbiosSSN_Analyzer::ConnectionClosed(tcp::TCP_Endpoint* endpoint, void NetbiosSSN_Analyzer::ConnectionClosed(tcp::TCP_Endpoint* endpoint,
tcp::TCP_Endpoint* peer, int gen_event) tcp::TCP_Endpoint* peer, bool gen_event)
{ {
tcp::TCP_ApplicationAnalyzer::ConnectionClosed(endpoint, peer, gen_event); tcp::TCP_ApplicationAnalyzer::ConnectionClosed(endpoint, peer, gen_event);
@ -521,9 +513,9 @@ void NetbiosSSN_Analyzer::DeliverPacket(int len, const u_char* data, bool orig,
tcp::TCP_ApplicationAnalyzer::DeliverPacket(len, data, orig, seq, ip, caplen); tcp::TCP_ApplicationAnalyzer::DeliverPacket(len, data, orig, seq, ip, caplen);
if ( orig ) if ( orig )
interp->ParseMessageUDP(data, len, 1); interp->ParseMessageUDP(data, len, true);
else else
interp->ParseMessageUDP(data, len, 0); interp->ParseMessageUDP(data, len, false);
} }
void NetbiosSSN_Analyzer::ExpireTimer(double t) void NetbiosSSN_Analyzer::ExpireTimer(double t)
@ -541,5 +533,5 @@ void NetbiosSSN_Analyzer::ExpireTimer(double t)
else else
ADD_ANALYZER_TIMER(&NetbiosSSN_Analyzer::ExpireTimer, ADD_ANALYZER_TIMER(&NetbiosSSN_Analyzer::ExpireTimer,
t + netbios_ssn_session_timeout, t + netbios_ssn_session_timeout,
1, TIMER_NB_EXPIRE); true, TIMER_NB_EXPIRE);
} }

View file

@ -65,28 +65,28 @@ class NetbiosSSN_Interpreter {
public: public:
explicit NetbiosSSN_Interpreter(Analyzer* analyzer); explicit NetbiosSSN_Interpreter(Analyzer* analyzer);
int ParseMessage(unsigned int type, unsigned int flags, void ParseMessage(unsigned int type, unsigned int flags,
const u_char* data, int len, int is_query); const u_char* data, int len, bool is_query);
// Version used when data points to type/flags/length. // Version used when data points to type/flags/length.
int ParseMessageTCP(const u_char* data, int len, int is_query); void ParseMessageTCP(const u_char* data, int len, bool is_query);
int ParseMessageUDP(const u_char* data, int len, int is_query); void ParseMessageUDP(const u_char* data, int len, bool is_query);
void Timeout() { } void Timeout() { }
protected: protected:
int ParseSessionMsg(const u_char* data, int len, int is_query); void ParseSessionMsg(const u_char* data, int len, bool is_query);
int ParseSessionReq(const u_char* data, int len, int is_query); void ParseSessionReq(const u_char* data, int len, bool is_query);
int ParseSessionPosResp(const u_char* data, int len, int is_query); void ParseSessionPosResp(const u_char* data, int len, bool is_query);
int ParseSessionNegResp(const u_char* data, int len, int is_query); void ParseSessionNegResp(const u_char* data, int len, bool is_query);
int ParseRetArgResp(const u_char* data, int len, int is_query); void ParseRetArgResp(const u_char* data, int len, bool is_query);
int ParseKeepAlive(const u_char* data, int len, int is_query); void ParseKeepAlive(const u_char* data, int len, bool is_query);
// Datagram parsing // Datagram parsing
int ParseBroadcast(const u_char* data, int len, int is_query); void ParseBroadcast(const u_char* data, int len, bool is_query);
int ParseDatagram(const u_char* data, int len, int is_query); void ParseDatagram(const u_char* data, int len, bool is_query);
int ParseSambaMsg(const u_char* data, int len, int is_query); void ParseSambaMsg(const u_char* data, int len, bool is_query);
void Event(EventHandlerPtr event, const u_char* data, int len, void Event(EventHandlerPtr event, const u_char* data, int len,
int is_orig = -1); int is_orig = -1);
@ -152,7 +152,7 @@ public:
protected: protected:
void ConnectionClosed(tcp::TCP_Endpoint* endpoint, void ConnectionClosed(tcp::TCP_Endpoint* endpoint,
tcp::TCP_Endpoint* peer, int gen_event) override; tcp::TCP_Endpoint* peer, bool gen_event) override;
void EndpointEOF(bool is_orig) override; void EndpointEOF(bool is_orig) override;
void ExpireTimer(double t); void ExpireTimer(double t);

View file

@ -78,7 +78,7 @@ void POP3_Analyzer::DeliverStream(int len, const u_char* data, bool orig)
if ( (TCP() && TCP()->IsPartial()) ) if ( (TCP() && TCP()->IsPartial()) )
return; return;
BroString terminated_string(data, len, 1); BroString terminated_string(data, len, true);
if ( orig ) if ( orig )
ProcessRequest(len, (char*) terminated_string.Bytes()); ProcessRequest(len, (char*) terminated_string.Bytes());
@ -860,7 +860,7 @@ void POP3_Analyzer::EndData()
void POP3_Analyzer::ProcessData(int length, const char* line) void POP3_Analyzer::ProcessData(int length, const char* line)
{ {
mail->Deliver(length, line, 1); mail->Deliver(length, line, true);
} }
int POP3_Analyzer::ParseCmd(string cmd) int POP3_Analyzer::ParseCmd(string cmd)

View file

@ -15,7 +15,7 @@
using namespace analyzer::rpc; using namespace analyzer::rpc;
int MOUNT_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) bool MOUNT_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n)
{ {
if ( c->Program() != 100005 ) if ( c->Program() != 100005 )
Weird("bad_RPC_program", fmt("%d", c->Program())); Weird("bad_RPC_program", fmt("%d", c->Program()));
@ -54,7 +54,7 @@ int MOUNT_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n)
// Return 1 so that replies to unprocessed calls will still // Return 1 so that replies to unprocessed calls will still
// be processed, and the return status extracted. // be processed, and the return status extracted.
return 1; return true;
} }
if ( ! buf ) if ( ! buf )
@ -66,15 +66,15 @@ int MOUNT_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n)
// Unref() the call arguments, and we are fine. // Unref() the call arguments, and we are fine.
Unref(callarg); Unref(callarg);
callarg = 0; callarg = 0;
return 0; return false;
} }
c->AddVal(callarg); // It's save to AddVal(0). c->AddVal(callarg); // It's save to AddVal(0).
return 1; return true;
} }
int MOUNT_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status, bool MOUNT_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status,
const u_char*& buf, int& n, double start_time, const u_char*& buf, int& n, double start_time,
double last_time, int reply_len) double last_time, int reply_len)
{ {
@ -143,7 +143,7 @@ int MOUNT_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status
event = mount_proc_not_implemented; event = mount_proc_not_implemented;
} }
else else
return 0; return false;
} }
if ( rpc_success && ! buf ) if ( rpc_success && ! buf )
@ -152,7 +152,7 @@ int MOUNT_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status
// also comments in RPC_BuildCall. // also comments in RPC_BuildCall.
Unref(reply); Unref(reply);
reply = 0; reply = 0;
return 0; return false;
} }
// Note: if reply == 0, it won't be added to the val_list for the // Note: if reply == 0, it won't be added to the val_list for the
@ -178,7 +178,7 @@ int MOUNT_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status
} }
else else
Unref(reply); Unref(reply);
return 1; return true;
} }
zeek::Args MOUNT_Interp::event_common_vl(RPC_CallInfo *c, zeek::Args MOUNT_Interp::event_common_vl(RPC_CallInfo *c,
@ -232,7 +232,7 @@ StringVal* MOUNT_Interp::mount3_fh(const u_char*& buf, int& n)
if ( ! fh ) if ( ! fh )
return 0; return 0;
return new StringVal(new BroString(fh, fh_n, 0)); return new StringVal(new BroString(fh, fh_n, false));
} }
StringVal* MOUNT_Interp::mount3_filename(const u_char*& buf, int& n) StringVal* MOUNT_Interp::mount3_filename(const u_char*& buf, int& n)
@ -243,7 +243,7 @@ StringVal* MOUNT_Interp::mount3_filename(const u_char*& buf, int& n)
if ( ! name ) if ( ! name )
return 0; return 0;
return new StringVal(new BroString(name, name_len, 0)); return new StringVal(new BroString(name, name_len, false));
} }
RecordVal* MOUNT_Interp::mount3_dirmntargs(const u_char*& buf, int& n) RecordVal* MOUNT_Interp::mount3_dirmntargs(const u_char*& buf, int& n)

View file

@ -11,8 +11,8 @@ public:
explicit MOUNT_Interp(analyzer::Analyzer* arg_analyzer) : RPC_Interpreter(arg_analyzer) { } explicit MOUNT_Interp(analyzer::Analyzer* arg_analyzer) : RPC_Interpreter(arg_analyzer) { }
protected: protected:
int RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) override; bool RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) override;
int RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status, bool RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status,
const u_char*& buf, int& n, double start_time, const u_char*& buf, int& n, double start_time,
double last_time, int reply_len) override; double last_time, int reply_len) override;

View file

@ -15,7 +15,7 @@
using namespace analyzer::rpc; using namespace analyzer::rpc;
int NFS_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) bool NFS_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n)
{ {
if ( c->Program() != 100003 ) if ( c->Program() != 100003 )
Weird("bad_RPC_program", fmt("%d", c->Program())); Weird("bad_RPC_program", fmt("%d", c->Program()));
@ -108,7 +108,7 @@ int NFS_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n)
// Return 1 so that replies to unprocessed calls will still // Return 1 so that replies to unprocessed calls will still
// be processed, and the return status extracted. // be processed, and the return status extracted.
return 1; return true;
} }
if ( ! buf ) if ( ! buf )
@ -120,15 +120,15 @@ int NFS_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n)
// Unref() the call arguments, and we are fine. // Unref() the call arguments, and we are fine.
Unref(callarg); Unref(callarg);
callarg = 0; callarg = 0;
return 0; return false;
} }
c->AddVal(callarg); // It's save to AddVal(0). c->AddVal(callarg); // It's save to AddVal(0).
return 1; return true;
} }
int NFS_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status, bool NFS_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status,
const u_char*& buf, int& n, double start_time, const u_char*& buf, int& n, double start_time,
double last_time, int reply_len) double last_time, int reply_len)
{ {
@ -255,7 +255,7 @@ int NFS_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status,
event = nfs_proc_not_implemented; event = nfs_proc_not_implemented;
} }
else else
return 0; return false;
} }
if ( rpc_success && ! buf ) if ( rpc_success && ! buf )
@ -264,7 +264,7 @@ int NFS_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status,
// also comments in RPC_BuildCall. // also comments in RPC_BuildCall.
Unref(reply); Unref(reply);
reply = 0; reply = 0;
return 0; return false;
} }
// Note: if reply == 0, it won't be added to the val_list for the // Note: if reply == 0, it won't be added to the val_list for the
@ -291,7 +291,7 @@ int NFS_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status,
else else
Unref(reply); Unref(reply);
return 1; return true;
} }
StringVal* NFS_Interp::nfs3_file_data(const u_char*& buf, int& n, uint64_t offset, int size) StringVal* NFS_Interp::nfs3_file_data(const u_char*& buf, int& n, uint64_t offset, int size)
@ -313,7 +313,7 @@ StringVal* NFS_Interp::nfs3_file_data(const u_char*& buf, int& n, uint64_t offse
data_n = min(data_n, int(BifConst::NFS3::return_data_max)); data_n = min(data_n, int(BifConst::NFS3::return_data_max));
if ( data && data_n > 0 ) if ( data && data_n > 0 )
return new StringVal(new BroString(data, data_n, 0)); return new StringVal(new BroString(data, data_n, false));
return 0; return 0;
} }
@ -360,7 +360,7 @@ StringVal* NFS_Interp::nfs3_fh(const u_char*& buf, int& n)
if ( ! fh ) if ( ! fh )
return 0; return 0;
return new StringVal(new BroString(fh, fh_n, 0)); return new StringVal(new BroString(fh, fh_n, false));
} }
@ -466,7 +466,7 @@ StringVal *NFS_Interp::nfs3_filename(const u_char*& buf, int& n)
if ( ! name ) if ( ! name )
return 0; return 0;
return new StringVal(new BroString(name, name_len, 0)); return new StringVal(new BroString(name, name_len, false));
} }
RecordVal *NFS_Interp::nfs3_diropargs(const u_char*& buf, int& n) RecordVal *NFS_Interp::nfs3_diropargs(const u_char*& buf, int& n)

View file

@ -12,8 +12,8 @@ public:
explicit NFS_Interp(analyzer::Analyzer* arg_analyzer) : RPC_Interpreter(arg_analyzer) { } explicit NFS_Interp(analyzer::Analyzer* arg_analyzer) : RPC_Interpreter(arg_analyzer) { }
protected: protected:
int RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) override; bool RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) override;
int RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status, bool RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status,
const u_char*& buf, int& n, double start_time, const u_char*& buf, int& n, double start_time,
double last_time, int reply_len) override; double last_time, int reply_len) override;

View file

@ -18,7 +18,7 @@ using namespace analyzer::rpc;
#define PMAPPROC_DUMP 4 #define PMAPPROC_DUMP 4
#define PMAPPROC_CALLIT 5 #define PMAPPROC_CALLIT 5
int PortmapperInterp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) bool PortmapperInterp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n)
{ {
if ( c->Program() != 100000 ) if ( c->Program() != 100000 )
Weird("bad_RPC_program"); Weird("bad_RPC_program");
@ -31,7 +31,7 @@ int PortmapperInterp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n)
{ {
Val* m = ExtractMapping(buf, n); Val* m = ExtractMapping(buf, n);
if ( ! m ) if ( ! m )
return 0; return false;
c->AddVal(m); c->AddVal(m);
} }
break; break;
@ -40,7 +40,7 @@ int PortmapperInterp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n)
{ {
Val* m = ExtractMapping(buf, n); Val* m = ExtractMapping(buf, n);
if ( ! m ) if ( ! m )
return 0; return false;
c->AddVal(m); c->AddVal(m);
} }
break; break;
@ -49,7 +49,7 @@ int PortmapperInterp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n)
{ {
Val* pr = ExtractPortRequest(buf, n); Val* pr = ExtractPortRequest(buf, n);
if ( ! pr ) if ( ! pr )
return 0; return false;
c->AddVal(pr); c->AddVal(pr);
} }
break; break;
@ -61,19 +61,19 @@ int PortmapperInterp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n)
{ {
Val* call_it = ExtractCallItRequest(buf, n); Val* call_it = ExtractCallItRequest(buf, n);
if ( ! call_it ) if ( ! call_it )
return 0; return false;
c->AddVal(call_it); c->AddVal(call_it);
} }
break; break;
default: default:
return 0; return false;
} }
return 1; return true;
} }
int PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status status, bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status status,
const u_char*& buf, int& n, const u_char*& buf, int& n,
double start_time, double last_time, double start_time, double last_time,
int reply_len) int reply_len)
@ -92,7 +92,7 @@ int PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status status
{ {
uint32_t status = extract_XDR_uint32(buf, n); uint32_t status = extract_XDR_uint32(buf, n);
if ( ! buf ) if ( ! buf )
return 0; return false;
reply = val_mgr->GetBool(status); reply = val_mgr->GetBool(status);
event = pm_request_set; event = pm_request_set;
@ -107,7 +107,7 @@ int PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status status
{ {
uint32_t status = extract_XDR_uint32(buf, n); uint32_t status = extract_XDR_uint32(buf, n);
if ( ! buf ) if ( ! buf )
return 0; return false;
reply = val_mgr->GetBool(status); reply = val_mgr->GetBool(status);
event = pm_request_unset; event = pm_request_unset;
@ -122,7 +122,7 @@ int PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status status
{ {
uint32_t port = extract_XDR_uint32(buf, n); uint32_t port = extract_XDR_uint32(buf, n);
if ( ! buf ) if ( ! buf )
return 0; return false;
RecordVal* rv = c->RequestVal()->AsRecordVal(); RecordVal* rv = c->RequestVal()->AsRecordVal();
Val* is_tcp = rv->Lookup(2); Val* is_tcp = rv->Lookup(2);
@ -158,7 +158,7 @@ int PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status status
if ( ! buf ) if ( ! buf )
{ {
Unref(mappings); Unref(mappings);
return 0; return false;
} }
reply = mappings; reply = mappings;
@ -176,7 +176,7 @@ int PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status status
const u_char* opaque_reply = const u_char* opaque_reply =
extract_XDR_opaque(buf, n, reply_n); extract_XDR_opaque(buf, n, reply_n);
if ( ! opaque_reply ) if ( ! opaque_reply )
return 0; return false;
reply = val_mgr->GetPort(CheckPort(port), TRANSPORT_UDP); reply = val_mgr->GetPort(CheckPort(port), TRANSPORT_UDP);
event = pm_request_callit; event = pm_request_callit;
@ -186,11 +186,11 @@ int PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status status
break; break;
default: default:
return 0; return false;
} }
Event(event, c->TakeRequestVal(), status, reply); Event(event, c->TakeRequestVal(), status, reply);
return 1; return true;
} }
Val* PortmapperInterp::ExtractMapping(const u_char*& buf, int& len) Val* PortmapperInterp::ExtractMapping(const u_char*& buf, int& len)
@ -200,7 +200,7 @@ Val* PortmapperInterp::ExtractMapping(const u_char*& buf, int& len)
mapping->Assign(0, val_mgr->GetCount(extract_XDR_uint32(buf, len))); mapping->Assign(0, val_mgr->GetCount(extract_XDR_uint32(buf, len)));
mapping->Assign(1, val_mgr->GetCount(extract_XDR_uint32(buf, len))); mapping->Assign(1, val_mgr->GetCount(extract_XDR_uint32(buf, len)));
int is_tcp = extract_XDR_uint32(buf, len) == IPPROTO_TCP; bool is_tcp = extract_XDR_uint32(buf, len) == IPPROTO_TCP;
uint32_t port = extract_XDR_uint32(buf, len); uint32_t port = extract_XDR_uint32(buf, len);
mapping->Assign(2, val_mgr->GetPort(CheckPort(port), mapping->Assign(2, val_mgr->GetPort(CheckPort(port),
is_tcp ? TRANSPORT_TCP : TRANSPORT_UDP)); is_tcp ? TRANSPORT_TCP : TRANSPORT_UDP));
@ -221,7 +221,7 @@ Val* PortmapperInterp::ExtractPortRequest(const u_char*& buf, int& len)
pr->Assign(0, val_mgr->GetCount(extract_XDR_uint32(buf, len))); pr->Assign(0, val_mgr->GetCount(extract_XDR_uint32(buf, len)));
pr->Assign(1, val_mgr->GetCount(extract_XDR_uint32(buf, len))); pr->Assign(1, val_mgr->GetCount(extract_XDR_uint32(buf, len)));
int is_tcp = extract_XDR_uint32(buf, len) == IPPROTO_TCP; bool is_tcp = extract_XDR_uint32(buf, len) == IPPROTO_TCP;
pr->Assign(2, val_mgr->GetBool(is_tcp)); pr->Assign(2, val_mgr->GetBool(is_tcp));
(void) extract_XDR_uint32(buf, len); // consume the bogus port (void) extract_XDR_uint32(buf, len); // consume the bogus port

View file

@ -11,8 +11,8 @@ public:
explicit PortmapperInterp(analyzer::Analyzer* arg_analyzer) : RPC_Interpreter(arg_analyzer) { } explicit PortmapperInterp(analyzer::Analyzer* arg_analyzer) : RPC_Interpreter(arg_analyzer) { }
protected: protected:
int RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) override; bool RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) override;
int RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status success, bool RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status success,
const u_char*& buf, int& n, double start_time, const u_char*& buf, int& n, double start_time,
double last_time, int reply_len) override; double last_time, int reply_len) override;
uint32_t CheckPort(uint32_t port); uint32_t CheckPort(uint32_t port);

Some files were not shown because too many files have changed in this diff Show more