Fix misc. issues reported by Coverity.

Some uninitialized values, a possible null pointer dereference, and
time-of-check-time-of-use on reading random seed file.
This commit is contained in:
Jon Siwek 2013-10-14 14:02:39 -05:00
parent 50784c64bc
commit 38ae7c98b4
10 changed files with 22 additions and 12 deletions

View file

@ -14,8 +14,11 @@
FlowSrc::FlowSrc() FlowSrc::FlowSrc()
{ // TODO: v9. { // TODO: v9.
selectable_fd = -1;
idle = false; idle = false;
data = 0; data = 0;
pdu_len = -1;
exporter_ip = 0;
current_timestamp = next_timestamp = 0.0; current_timestamp = next_timestamp = 0.0;
netflow_analyzer = new binpac::NetFlow::NetFlow_Analyzer(); netflow_analyzer = new binpac::NetFlow::NetFlow_Analyzer();
} }

View file

@ -17,6 +17,9 @@ PacketSortElement::PacketSortElement(PktSrc* arg_src,
is_tcp = 0; is_tcp = 0;
ip_hdr = 0; ip_hdr = 0;
tcp_flags = 0;
endp = 0;
payload_length = 0;
key = 0; key = 0;
// Now check if it is a "parsable" TCP packet. // Now check if it is a "parsable" TCP packet.

View file

@ -113,7 +113,8 @@ protected:
conns = 0; conns = 0;
conn_cookie = 0; conn_cookie = 0;
peer = SOURCE_LOCAL; peer = SOURCE_LOCAL;
}; filename = 0;
}
Type type; Type type;
SerialInfo info; SerialInfo info;

View file

@ -648,6 +648,7 @@ PktDumper::PktDumper(const char* arg_filename, bool arg_append)
is_error = false; is_error = false;
append = arg_append; append = arg_append;
dumper = 0; dumper = 0;
open_time = 0.0;
// We need a pcap_t with a reasonable link-layer type. We try to get it // We need a pcap_t with a reasonable link-layer type. We try to get it
// from the packet sources. If not available, we fall back to Ethernet. // from the packet sources. If not available, we fall back to Ethernet.

View file

@ -86,6 +86,7 @@ bool LoadPolicyFileText(const char* policy_filename)
char buf[256]; char buf[256];
strerror_r(errno, buf, sizeof(buf)); strerror_r(errno, buf, sizeof(buf));
reporter->Error("fstat failed on %s: %s", policy_filename, buf); reporter->Error("fstat failed on %s: %s", policy_filename, buf);
fclose(f);
return false; return false;
} }

View file

@ -3321,6 +3321,9 @@ SocketComm::SocketComm()
id_counter = 10000; id_counter = 10000;
parent_peer = 0; parent_peer = 0;
parent_msgstate = TYPE; parent_msgstate = TYPE;
parent_id = RemoteSerializer::PEER_NONE;
parent_msgtype = 0;
parent_args = 0;
shutting_conns_down = false; shutting_conns_down = false;
terminating = false; terminating = false;
killing = false; killing = false;

View file

@ -31,8 +31,11 @@ flow NetFlow_Flow {
internal_type("nf_v5_record")->AsRecordType(); internal_type("nf_v5_record")->AsRecordType();
nfheader_id_type = nfheader_id_type =
internal_type("nfheader_id")->AsRecordType(); internal_type("nfheader_id")->AsRecordType();
pdu_id = 0;
identifier = NULL; identifier = NULL;
exporter_ip = 0;
uptime = 0;
export_time = 0;
pdu_id = 0;
%} %}
# %cleanup does not only put the cleanup code into the destructor, # %cleanup does not only put the cleanup code into the destructor,

View file

@ -1518,7 +1518,6 @@ int Manager::PutTable(Stream* i, const Value* const *vals)
EnumVal* ev; EnumVal* ev;
int startpos = 0; int startpos = 0;
Val* predidx = ValueToRecordVal(vals, stream->itype, &startpos); Val* predidx = ValueToRecordVal(vals, stream->itype, &startpos);
Ref(valval);
if ( updated ) if ( updated )
ev = new EnumVal(BifEnum::Input::EVENT_CHANGED, ev = new EnumVal(BifEnum::Input::EVENT_CHANGED,
@ -1529,7 +1528,10 @@ int Manager::PutTable(Stream* i, const Value* const *vals)
bool result; bool result;
if ( stream->num_val_fields > 0 ) // we have values if ( stream->num_val_fields > 0 ) // we have values
{
Ref(valval);
result = CallPred(stream->pred, 3, ev, predidx, valval); result = CallPred(stream->pred, 3, ev, predidx, valval);
}
else // no values else // no values
result = CallPred(stream->pred, 2, ev, predidx); result = CallPred(stream->pred, 2, ev, predidx);

View file

@ -289,7 +289,8 @@ bool Raw::OpenInput()
return false; return false;
} }
fcntl(fileno(file), F_SETFD, FD_CLOEXEC); if ( ! SetFDFlags(fileno(file), F_SETFD, FD_CLOEXEC) )
Warning(Fmt("Init: cannot set close-on-exec for %s", fname.c_str()));
} }
return true; return true;

View file

@ -652,16 +652,8 @@ void hmac_md5(size_t size, const unsigned char* bytes, unsigned char digest[16])
static bool read_random_seeds(const char* read_file, uint32* seed, static bool read_random_seeds(const char* read_file, uint32* seed,
uint32* buf, int bufsiz) uint32* buf, int bufsiz)
{ {
struct stat st;
FILE* f = 0; FILE* f = 0;
if ( stat(read_file, &st) < 0 )
{
reporter->Warning("Seed file '%s' does not exist: %s",
read_file, strerror(errno));
return false;
}
if ( ! (f = fopen(read_file, "r")) ) if ( ! (f = fopen(read_file, "r")) )
{ {
reporter->Warning("Could not open seed file '%s': %s", reporter->Warning("Could not open seed file '%s': %s",