mirror of
https://github.com/zeek/zeek.git
synced 2025-10-06 08:38:20 +00:00
Fixing a few cases of undefined behaviour introduced by recent
formatter work. Thanks, Coverity!
This commit is contained in:
parent
17f9d0a47d
commit
8b241947d6
7 changed files with 21 additions and 15 deletions
|
@ -51,6 +51,7 @@ Ascii::Ascii(ReaderFrontend *frontend) : ReaderBackend(frontend)
|
||||||
{
|
{
|
||||||
file = 0;
|
file = 0;
|
||||||
mtime = 0;
|
mtime = 0;
|
||||||
|
formatter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ascii::~Ascii()
|
Ascii::~Ascii()
|
||||||
|
|
|
@ -20,6 +20,7 @@ Ascii::Ascii(WriterFrontend* frontend) : WriterBackend(frontend)
|
||||||
fd = 0;
|
fd = 0;
|
||||||
ascii_done = false;
|
ascii_done = false;
|
||||||
tsv = false;
|
tsv = false;
|
||||||
|
formatter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ascii::~Ascii()
|
Ascii::~Ascii()
|
||||||
|
|
|
@ -76,7 +76,7 @@ public:
|
||||||
* @return The new value, or null on error. Errors must also be
|
* @return The new value, or null on error. Errors must also be
|
||||||
* flagged via the thread.
|
* flagged via the thread.
|
||||||
*/
|
*/
|
||||||
virtual threading::Value* ParseValue(string s, string name, TypeTag type, TypeTag subtype = TYPE_ERROR) const = 0;
|
virtual threading::Value* ParseValue(const string& s, const string& name, TypeTag type, TypeTag subtype = TYPE_ERROR) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert an IP address into a string.
|
* Convert an IP address into a string.
|
||||||
|
|
|
@ -201,7 +201,7 @@ bool Ascii::Describe(ODesc* desc, threading::Value* val, const string& name) con
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
threading::Value* Ascii::ParseValue(string s, string name, TypeTag type, TypeTag subtype) const
|
threading::Value* Ascii::ParseValue(const string& s, const string& name, TypeTag type, TypeTag subtype) const
|
||||||
{
|
{
|
||||||
if ( s.compare(separators.unset_field) == 0 ) // field is not set...
|
if ( s.compare(separators.unset_field) == 0 ) // field is not set...
|
||||||
return new threading::Value(type, false);
|
return new threading::Value(type, false);
|
||||||
|
@ -214,10 +214,12 @@ threading::Value* Ascii::ParseValue(string s, string name, TypeTag type, TypeTag
|
||||||
switch ( type ) {
|
switch ( type ) {
|
||||||
case TYPE_ENUM:
|
case TYPE_ENUM:
|
||||||
case TYPE_STRING:
|
case TYPE_STRING:
|
||||||
s = get_unescaped_string(s);
|
{
|
||||||
val->val.string_val.length = s.size();
|
string unescaped = get_unescaped_string(s);
|
||||||
val->val.string_val.data = copy_string(s.c_str());
|
val->val.string_val.length = unescaped.size();
|
||||||
|
val->val.string_val.data = copy_string(unescaped.c_str());
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case TYPE_BOOL:
|
case TYPE_BOOL:
|
||||||
if ( s == "T" )
|
if ( s == "T" )
|
||||||
|
@ -263,21 +265,21 @@ threading::Value* Ascii::ParseValue(string s, string name, TypeTag type, TypeTag
|
||||||
|
|
||||||
case TYPE_SUBNET:
|
case TYPE_SUBNET:
|
||||||
{
|
{
|
||||||
s = get_unescaped_string(s);
|
string unescaped = get_unescaped_string(s);
|
||||||
size_t pos = s.find("/");
|
size_t pos = unescaped.find("/");
|
||||||
if ( pos == s.npos )
|
if ( pos == unescaped.npos )
|
||||||
{
|
{
|
||||||
GetThread()->Error(GetThread()->Fmt("Invalid value for subnet: %s", start));
|
GetThread()->Error(GetThread()->Fmt("Invalid value for subnet: %s", start));
|
||||||
goto parse_error;
|
goto parse_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
string width_str = s.substr(pos + 1);
|
string width_str = unescaped.substr(pos + 1);
|
||||||
uint8_t width = (uint8_t) strtol(width_str.c_str(), &end, 10);
|
uint8_t width = (uint8_t) strtol(width_str.c_str(), &end, 10);
|
||||||
|
|
||||||
if ( CheckNumberError(start, end) )
|
if ( CheckNumberError(start, end) )
|
||||||
goto parse_error;
|
goto parse_error;
|
||||||
|
|
||||||
string addr = s.substr(0, pos);
|
string addr = unescaped.substr(0, pos);
|
||||||
|
|
||||||
val->val.subnet_val.prefix = ParseAddr(addr);
|
val->val.subnet_val.prefix = ParseAddr(addr);
|
||||||
val->val.subnet_val.length = width;
|
val->val.subnet_val.length = width;
|
||||||
|
@ -285,9 +287,11 @@ threading::Value* Ascii::ParseValue(string s, string name, TypeTag type, TypeTag
|
||||||
}
|
}
|
||||||
|
|
||||||
case TYPE_ADDR:
|
case TYPE_ADDR:
|
||||||
s = get_unescaped_string(s);
|
{
|
||||||
val->val.addr_val = ParseAddr(s);
|
string unescaped = get_unescaped_string(s);
|
||||||
|
val->val.addr_val = ParseAddr(unescaped);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case TYPE_TABLE:
|
case TYPE_TABLE:
|
||||||
case TYPE_VECTOR:
|
case TYPE_VECTOR:
|
||||||
|
|
|
@ -50,7 +50,7 @@ public:
|
||||||
virtual bool Describe(ODesc* desc, threading::Value* val, const string& name = "") const;
|
virtual bool Describe(ODesc* desc, threading::Value* val, const string& name = "") const;
|
||||||
virtual bool Describe(ODesc* desc, int num_fields, const threading::Field* const * fields,
|
virtual bool Describe(ODesc* desc, int num_fields, const threading::Field* const * fields,
|
||||||
threading::Value** vals) const;
|
threading::Value** vals) const;
|
||||||
virtual threading::Value* ParseValue(string s, string name, TypeTag type, TypeTag subtype = TYPE_ERROR) const;
|
virtual threading::Value* ParseValue(const string& s, const string& name, TypeTag type, TypeTag subtype = TYPE_ERROR) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool CheckNumberError(const char* start, const char* end) const;
|
bool CheckNumberError(const char* start, const char* end) const;
|
||||||
|
|
|
@ -212,7 +212,7 @@ bool JSON::Describe(ODesc* desc, Value* val, const string& name) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
threading::Value* JSON::ParseValue(string s, string name, TypeTag type, TypeTag subtype) const
|
threading::Value* JSON::ParseValue(const string& s, const string& name, TypeTag type, TypeTag subtype) const
|
||||||
{
|
{
|
||||||
GetThread()->Error("JSON formatter does not support parsing yet.");
|
GetThread()->Error("JSON formatter does not support parsing yet.");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -25,7 +25,7 @@ public:
|
||||||
virtual bool Describe(ODesc* desc, threading::Value* val, const string& name = "") const;
|
virtual bool Describe(ODesc* desc, threading::Value* val, const string& name = "") const;
|
||||||
virtual bool Describe(ODesc* desc, int num_fields, const threading::Field* const * fields,
|
virtual bool Describe(ODesc* desc, int num_fields, const threading::Field* const * fields,
|
||||||
threading::Value** vals) const;
|
threading::Value** vals) const;
|
||||||
virtual threading::Value* ParseValue(string s, string name, TypeTag type, TypeTag subtype = TYPE_ERROR) const;
|
virtual threading::Value* ParseValue(const string& s, const string& name, TypeTag type, TypeTag subtype = TYPE_ERROR) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TimeFormat timestamps;
|
TimeFormat timestamps;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue