Fix/improve dereference-before-null-checks.

This commit is contained in:
Jon Siwek 2013-09-13 16:41:41 -05:00
parent 3d81432a1e
commit 735d2c402a
8 changed files with 19 additions and 30 deletions

View file

@ -1074,9 +1074,8 @@ bool ChunkedIOSSL::Read(Chunk** chunk, bool mayblock)
read_state = LEN; read_state = LEN;
#ifdef DEBUG #ifdef DEBUG
if ( *chunk ) DBG_LOG(DBG_CHUNKEDIO, "ssl read of size %d [%s]",
DBG_LOG(DBG_CHUNKEDIO, "ssl read of size %d [%s]", (*chunk)->len, fmt_bytes((*chunk)->data, 20));
(*chunk)->len, fmt_bytes((*chunk)->data, 20));
#endif #endif
return true; return true;

View file

@ -23,11 +23,7 @@ ODesc::ODesc(desc_type t, BroFile* arg_f)
size = DEFAULT_SIZE; size = DEFAULT_SIZE;
base = safe_malloc(size); base = safe_malloc(size);
((char*) base)[0] = '\0'; ((char*) base)[0] = '\0';
offset = 0; offset = 0;
if ( ! base )
OutOfMemory();
} }
else else
{ {
@ -337,16 +333,9 @@ void ODesc::Grow(unsigned int n)
{ {
size *= 2; size *= 2;
base = safe_realloc(base, size); base = safe_realloc(base, size);
if ( ! base )
OutOfMemory();
} }
} }
void ODesc::OutOfMemory()
{
reporter->InternalError("out of memory");
}
void ODesc::Clear() void ODesc::Clear()
{ {
offset = 0; offset = 0;

View file

@ -149,8 +149,6 @@ protected:
// Make buffer big enough for n bytes beyond bufp. // Make buffer big enough for n bytes beyond bufp.
void Grow(unsigned int n); void Grow(unsigned int n);
void OutOfMemory();
/** /**
* Returns the location of the first place in the bytes to be hex-escaped. * Returns the location of the first place in the bytes to be hex-escaped.
* *

View file

@ -2925,8 +2925,7 @@ void RemoteSerializer::GotID(ID* id, Val* val)
const char* desc = val->AsString()->CheckString(); const char* desc = val->AsString()->CheckString();
current_peer->val->Assign(4, new StringVal(desc)); current_peer->val->Assign(4, new StringVal(desc));
Log(LogInfo, fmt("peer_description is %s", Log(LogInfo, fmt("peer_description is %s", *desc ? desc : "not set"),
(desc && *desc) ? desc : "not set"),
current_peer); current_peer);
Unref(id); Unref(id);

View file

@ -378,7 +378,7 @@ bool Serializer::UnserializeCall(UnserialInfo* info)
ignore = true; ignore = true;
} }
if ( info->print && types && ! ignore ) if ( info->print && ! ignore )
v->Describe(&d); v->Describe(&d);
} }

View file

@ -147,10 +147,12 @@ void PIA_UDP::ActivateAnalyzer(analyzer::Tag tag, const Rule* rule)
return; return;
analyzer::Analyzer* a = Parent()->AddChildAnalyzer(tag); analyzer::Analyzer* a = Parent()->AddChildAnalyzer(tag);
a->SetSignature(rule);
if ( a ) if ( ! a )
ReplayPacketBuffer(a); return;
a->SetSignature(rule);
ReplayPacketBuffer(a);
} }
void PIA_UDP::DeactivateAnalyzer(analyzer::Tag tag) void PIA_UDP::DeactivateAnalyzer(analyzer::Tag tag)

View file

@ -291,6 +291,12 @@ bool Raw::CloseInput()
bool Raw::DoInit(const ReaderInfo& info, int num_fields, const Field* const* fields) bool Raw::DoInit(const ReaderInfo& info, int num_fields, const Field* const* fields)
{ {
if ( ! info.source || strlen(info.source) == 0 )
{
Error("No source path provided");
return false;
}
fname = info.source; fname = info.source;
mtime = 0; mtime = 0;
execute = false; execute = false;
@ -298,7 +304,6 @@ bool Raw::DoInit(const ReaderInfo& info, int num_fields, const Field* const* fie
int want_fields = 1; int want_fields = 1;
bool result; bool result;
// do Initialization
string source = string(info.source); string source = string(info.source);
char last = info.source[source.length() - 1]; char last = info.source[source.length() - 1];
if ( last == '|' ) if ( last == '|' )
@ -307,12 +312,6 @@ bool Raw::DoInit(const ReaderInfo& info, int num_fields, const Field* const* fie
fname = source.substr(0, fname.length() - 1); fname = source.substr(0, fname.length() - 1);
} }
if ( ! info.source || strlen(info.source) == 0 )
{
Error("No source path provided");
return false;
}
map<const char*, const char*>::const_iterator it = info.config.find("stdin"); // data that is sent to the child process map<const char*, const char*>::const_iterator it = info.config.find("stdin"); // data that is sent to the child process
if ( it != info.config.end() ) if ( it != info.config.end() )
{ {

View file

@ -187,11 +187,14 @@ Value* SQLite::EntryToVal(sqlite3_stmt *st, const threading::Field *field, int p
if ( subpos != -1 ) if ( subpos != -1 )
{ {
const char *text = (const char*) sqlite3_column_text(st, subpos); const char *text = (const char*) sqlite3_column_text(st, subpos);
string s(text, sqlite3_column_bytes(st, subpos));
if ( text == 0 ) if ( text == 0 )
Error("Port protocol definition did not contain text"); Error("Port protocol definition did not contain text");
else else
{
string s(text, sqlite3_column_bytes(st, subpos));
val->val.port_val.proto = io->ParseProto(s); val->val.port_val.proto = io->ParseProto(s);
}
} }
break; break;
} }