Merge remote-tracking branch 'origin/topic/jsiwek/coverity'

* origin/topic/jsiwek/coverity:
  Fix uninitialized (or unused) fields.
  Remove logically dead code.
  Remove dead/unfinished code in unary not expr.
  Fix logic for failed DNS TXT lookups.
  A couple null ptr checks.
  Improve return value checking and error handling.
  Remove unused variable assignments, dead code.
  Prevent division/modulo by zero in scripts.
  Fix unintentional always-false condition.
  Fix invalidated iterator usage.
  Fix DNS_Mgr iterator mismatch.
  Set safe umask when creating script profiler tmp files.
  Fix nesting/indent level whitespace mismatch.
  Add checks to avoid improper negative values use.

BIT-1085 #merged
This commit is contained in:
Robin Sommer 2013-10-02 11:03:29 -07:00
commit d127d8d01d
86 changed files with 517 additions and 242 deletions

View file

@ -84,16 +84,16 @@ public:
RecordVal* description;
Stream();
virtual ~Stream();
protected:
Stream(StreamType t);
};
Manager::Stream::Stream()
Manager::Stream::Stream(StreamType t)
: name(), removed(), stream_type(t), type(), reader(), config(),
description()
{
type = 0;
reader = 0;
description = 0;
removed = false;
}
Manager::Stream::~Stream()
@ -154,24 +154,17 @@ public:
~AnalysisStream();
};
Manager::TableStream::TableStream() : Manager::Stream::Stream()
Manager::TableStream::TableStream()
: Manager::Stream::Stream(TABLE_STREAM),
num_idx_fields(), num_val_fields(), want_record(), tab(), rtype(),
itype(), currDict(), lastDict(), pred(), event()
{
stream_type = TABLE_STREAM;
tab = 0;
itype = 0;
rtype = 0;
currDict = 0;
lastDict = 0;
pred = 0;
}
Manager::EventStream::EventStream() : Manager::Stream::Stream()
Manager::EventStream::EventStream()
: Manager::Stream::Stream(EVENT_STREAM),
event(), fields(), num_fields(), want_record()
{
fields = 0;
stream_type = EVENT_STREAM;
}
Manager::EventStream::~EventStream()
@ -204,9 +197,9 @@ Manager::TableStream::~TableStream()
}
}
Manager::AnalysisStream::AnalysisStream() : Manager::Stream::Stream()
Manager::AnalysisStream::AnalysisStream()
: Manager::Stream::Stream(ANALYSIS_STREAM), file_id()
{
stream_type = ANALYSIS_STREAM;
}
Manager::AnalysisStream::~AnalysisStream()
@ -296,7 +289,7 @@ bool Manager::CreateStream(Stream* info, RecordVal* description)
return false;
}
Val* name_val = description->LookupWithDefault(rtype->FieldOffset("name"));
Val* name_val = description->Lookup("name", true);
string name = name_val->AsString()->CheckString();
Unref(name_val);
@ -308,10 +301,10 @@ bool Manager::CreateStream(Stream* info, RecordVal* description)
return false;
}
EnumVal* reader = description->LookupWithDefault(rtype->FieldOffset("reader"))->AsEnumVal();
EnumVal* reader = description->Lookup("reader", true)->AsEnumVal();
// get the source ...
Val* sourceval = description->LookupWithDefault(rtype->FieldOffset("source"));
Val* sourceval = description->Lookup("source", true);
assert ( sourceval != 0 );
const BroString* bsource = sourceval->AsString();
string source((const char*) bsource->Bytes(), bsource->Len());
@ -321,7 +314,7 @@ bool Manager::CreateStream(Stream* info, RecordVal* description)
rinfo.source = copy_string(source.c_str());
rinfo.name = copy_string(name.c_str());
EnumVal* mode = description->LookupWithDefault(rtype->FieldOffset("mode"))->AsEnumVal();
EnumVal* mode = description->Lookup("mode", true)->AsEnumVal();
switch ( mode->InternalInt() )
{
case 0:
@ -342,7 +335,7 @@ bool Manager::CreateStream(Stream* info, RecordVal* description)
Unref(mode);
Val* config = description->LookupWithDefault(rtype->FieldOffset("config"));
Val* config = description->Lookup("config", true);
info->config = config->AsTableVal(); // ref'd by LookupWithDefault
{
@ -401,11 +394,11 @@ bool Manager::CreateEventStream(RecordVal* fval)
}
RecordType *fields = fval->LookupWithDefault(rtype->FieldOffset("fields"))->AsType()->AsTypeType()->Type()->AsRecordType();
RecordType *fields = fval->Lookup("fields", true)->AsType()->AsTypeType()->Type()->AsRecordType();
Val *want_record = fval->LookupWithDefault(rtype->FieldOffset("want_record"));
Val *want_record = fval->Lookup("want_record", true);
Val* event_val = fval->LookupWithDefault(rtype->FieldOffset("ev"));
Val* event_val = fval->Lookup("ev", true);
Func* event = event_val->AsFunc();
Unref(event_val);
@ -547,18 +540,18 @@ bool Manager::CreateTableStream(RecordVal* fval)
}
}
Val* pred = fval->LookupWithDefault(rtype->FieldOffset("pred"));
Val* pred = fval->Lookup("pred", true);
RecordType *idx = fval->LookupWithDefault(rtype->FieldOffset("idx"))->AsType()->AsTypeType()->Type()->AsRecordType();
RecordType *idx = fval->Lookup("idx", true)->AsType()->AsTypeType()->Type()->AsRecordType();
RecordType *val = 0;
if ( fval->LookupWithDefault(rtype->FieldOffset("val")) != 0 )
if ( fval->Lookup("val", true) != 0 )
{
val = fval->LookupWithDefault(rtype->FieldOffset("val"))->AsType()->AsTypeType()->Type()->AsRecordType();
val = fval->Lookup("val", true)->AsType()->AsTypeType()->Type()->AsRecordType();
Unref(val); // The lookupwithdefault in the if-clause ref'ed val.
}
TableVal *dst = fval->LookupWithDefault(rtype->FieldOffset("destination"))->AsTableVal();
TableVal *dst = fval->Lookup("destination", true)->AsTableVal();
// check if index fields match table description
int num = idx->NumFields();
@ -588,9 +581,9 @@ bool Manager::CreateTableStream(RecordVal* fval)
return false;
}
Val *want_record = fval->LookupWithDefault(rtype->FieldOffset("want_record"));
Val *want_record = fval->Lookup("want_record", true);
Val* event_val = fval->LookupWithDefault(rtype->FieldOffset("ev"));
Val* event_val = fval->Lookup("ev", true);
Func* event = event_val ? event_val->AsFunc() : 0;
Unref(event_val);
@ -1153,7 +1146,6 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals)
{
// just quit and delete everything we created.
delete idxhash;
delete h;
return stream->num_val_fields + stream->num_idx_fields;
}