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;
|
||||
mtime = 0;
|
||||
formatter = 0;
|
||||
}
|
||||
|
||||
Ascii::~Ascii()
|
||||
|
|
|
@ -20,6 +20,7 @@ Ascii::Ascii(WriterFrontend* frontend) : WriterBackend(frontend)
|
|||
fd = 0;
|
||||
ascii_done = false;
|
||||
tsv = false;
|
||||
formatter = 0;
|
||||
}
|
||||
|
||||
Ascii::~Ascii()
|
||||
|
|
|
@ -76,7 +76,7 @@ public:
|
|||
* @return The new value, or null on error. Errors must also be
|
||||
* 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.
|
||||
|
|
|
@ -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...
|
||||
return new threading::Value(type, false);
|
||||
|
@ -214,10 +214,12 @@ threading::Value* Ascii::ParseValue(string s, string name, TypeTag type, TypeTag
|
|||
switch ( type ) {
|
||||
case TYPE_ENUM:
|
||||
case TYPE_STRING:
|
||||
s = get_unescaped_string(s);
|
||||
val->val.string_val.length = s.size();
|
||||
val->val.string_val.data = copy_string(s.c_str());
|
||||
{
|
||||
string unescaped = get_unescaped_string(s);
|
||||
val->val.string_val.length = unescaped.size();
|
||||
val->val.string_val.data = copy_string(unescaped.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
case TYPE_BOOL:
|
||||
if ( s == "T" )
|
||||
|
@ -263,21 +265,21 @@ threading::Value* Ascii::ParseValue(string s, string name, TypeTag type, TypeTag
|
|||
|
||||
case TYPE_SUBNET:
|
||||
{
|
||||
s = get_unescaped_string(s);
|
||||
size_t pos = s.find("/");
|
||||
if ( pos == s.npos )
|
||||
string unescaped = get_unescaped_string(s);
|
||||
size_t pos = unescaped.find("/");
|
||||
if ( pos == unescaped.npos )
|
||||
{
|
||||
GetThread()->Error(GetThread()->Fmt("Invalid value for subnet: %s", start));
|
||||
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);
|
||||
|
||||
if ( CheckNumberError(start, end) )
|
||||
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.length = width;
|
||||
|
@ -285,9 +287,11 @@ threading::Value* Ascii::ParseValue(string s, string name, TypeTag type, TypeTag
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
case TYPE_TABLE:
|
||||
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, int num_fields, const threading::Field* const * fields,
|
||||
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:
|
||||
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;
|
||||
}
|
||||
|
||||
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.");
|
||||
return NULL;
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
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,
|
||||
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:
|
||||
TimeFormat timestamps;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue