From e390244442102b17e480675fe8d3d7728bc5e6ad Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Mon, 8 Jul 2019 15:18:13 -0700 Subject: [PATCH 1/4] Remove unused variable from RecordVal (Coverity-1402820) --- src/Val.cc | 2 +- src/Val.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Val.cc b/src/Val.cc index 32d64c5cdd..57bfbb3a5e 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -2020,7 +2020,7 @@ vector RecordVal::parse_time_records; RecordVal::RecordVal(RecordType* t, bool init_fields) : Val(t) { - origin = 0; + origin = nullptr; int n = t->NumFields(); val_list* vl = val.val_list_val = new val_list(n); diff --git a/src/Val.h b/src/Val.h index 2ce61100b5..3b895dab14 100644 --- a/src/Val.h +++ b/src/Val.h @@ -981,7 +981,6 @@ protected: Val* DoClone(CloneState* state) override; - RecordType* record_type; BroObj* origin; static vector parse_time_records; From 4db6d00372b0e78fee721a9054cd3626c9e43a33 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Mon, 8 Jul 2019 15:18:54 -0700 Subject: [PATCH 2/4] Avoid null dereference in broker (Coverity-1402824, Coverity-1402814) --- src/broker/Data.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 657ddd3551..8572745474 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -1200,6 +1200,9 @@ bool bro_broker::VectorIterator::DoUnserialize(const broker::data& data) auto x = caf::get_if(&(*v)[0]); auto y = caf::get_if(&(*v)[1]); + if ( ! (x && y) ) + return false; + dat = *x; it = dat.begin() + *y; return true; @@ -1222,6 +1225,9 @@ bool bro_broker::RecordIterator::DoUnserialize(const broker::data& data) auto x = caf::get_if(&(*v)[0]); auto y = caf::get_if(&(*v)[1]); + if ( ! (x && y) ) + return false; + dat = *x; it = dat.begin() + *y; return true; From 69023a0c755fcb6499d5f6b25e5ef20ebb52a494 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Mon, 8 Jul 2019 15:19:32 -0700 Subject: [PATCH 3/4] Avoid resource leaks (Coverity-1402818, Coverity-1402812) --- src/probabilistic/Topk.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/probabilistic/Topk.cc b/src/probabilistic/Topk.cc index 8ff158e10d..29f47ec753 100644 --- a/src/probabilistic/Topk.cc +++ b/src/probabilistic/Topk.cc @@ -492,25 +492,25 @@ bool TopkVal::DoUnserialize(const broker::data& data) while ( i < numElements ) { - Bucket* b = new Bucket(); auto elements_count = caf::get_if(&(*v)[idx++]); auto count = caf::get_if(&(*v)[idx++]); if ( ! (elements_count && count) ) return false; + Bucket* b = new Bucket(); b->count = *count; b->bucketPos = buckets.insert(buckets.end(), b); for ( uint64_t j = 0; j < *elements_count; j++ ) { - Element* e = new Element(); auto epsilon = caf::get_if(&(*v)[idx++]); Val* val = bro_broker::data_to_val((*v)[idx++], type); if ( ! (epsilon && val) ) return false; + Element* e = new Element(); e->epsilon = *epsilon; e->value = val; e->parent = b; From 1af2640f4bb84ccf336f6993c6184042dcedea62 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Mon, 8 Jul 2019 16:13:16 -0700 Subject: [PATCH 4/4] Avoid a null dereference (Coverity-1402816) --- src/probabilistic/CounterVector.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/probabilistic/CounterVector.cc b/src/probabilistic/CounterVector.cc index b9a173356e..6b5a6ed92e 100644 --- a/src/probabilistic/CounterVector.cc +++ b/src/probabilistic/CounterVector.cc @@ -179,6 +179,9 @@ std::unique_ptr CounterVector::Unserialize(const broker::data& da auto width = caf::get_if(&(*v)[0]); auto bits = BitVector::Unserialize((*v)[1]); + if ( ! (width && bits) ) + return nullptr; + auto cv = std::unique_ptr(new CounterVector()); cv->width = *width; cv->bits = bits.release();