mirror of
https://github.com/zeek/zeek.git
synced 2025-10-03 23:28:20 +00:00
Merge remote-tracking branch 'origin/topic/bernhard/input-fixes'
* origin/topic/bernhard/input-fixes: fix problem with possible access to unititialized memory (thanks robin :) ) and just to be a little bit careful - add check if the field description is long enough. Otherwise there might possibly be an access of uninitialized memory, when someone reads a file that contains just #fields without any following field descriptions. and like nearly always - forgot the baseline. Input framework now accepts escaped ascii values as input. make reading ascii logfiles work when the input separator is different from \t.
This commit is contained in:
commit
f5214c0793
5 changed files with 66 additions and 19 deletions
|
@ -144,7 +144,7 @@ bool Ascii::ReadHeader(bool useCached)
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf("Updating fields from description %s\n", line.c_str());
|
// printf("Updating fields from description %s\n", line.c_str());
|
||||||
columnMap.clear();
|
columnMap.clear();
|
||||||
|
|
||||||
for ( int i = 0; i < NumFields(); i++ )
|
for ( int i = 0; i < NumFields(); i++ )
|
||||||
|
@ -199,7 +199,7 @@ bool Ascii::GetLine(string& str)
|
||||||
if ( str[0] != '#' )
|
if ( str[0] != '#' )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if ( str.compare(0,8, "#fields\t") == 0 )
|
if ( ( str.length() > 8 ) && ( str.compare(0,7, "#fields") == 0 ) && ( str[7] == separator[0] ) )
|
||||||
{
|
{
|
||||||
str = str.substr(8);
|
str = str.substr(8);
|
||||||
return true;
|
return true;
|
||||||
|
@ -438,6 +438,8 @@ bool Ascii::DoUpdate()
|
||||||
if ( ! getline(splitstream, s, separator[0]) )
|
if ( ! getline(splitstream, s, separator[0]) )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
s = get_unescaped_string(s);
|
||||||
|
|
||||||
stringfields[pos] = s;
|
stringfields[pos] = s;
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
|
|
42
src/util.cc
42
src/util.cc
|
@ -42,6 +42,44 @@
|
||||||
#include "Net.h"
|
#include "Net.h"
|
||||||
#include "Reporter.h"
|
#include "Reporter.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes a string, unescapes all characters that are escaped as hex codes
|
||||||
|
* (\x##) and turns them into the equivalent ascii-codes. Returns a string
|
||||||
|
* containing no escaped values
|
||||||
|
*
|
||||||
|
* @param str string to unescape
|
||||||
|
* @return A str::string without escaped characters.
|
||||||
|
*/
|
||||||
|
std::string get_unescaped_string(const std::string& arg_str)
|
||||||
|
{
|
||||||
|
const char* str = arg_str.c_str();
|
||||||
|
char* buf = new char [arg_str.length() + 1]; // it will at most have the same length as str.
|
||||||
|
char* bufpos = buf;
|
||||||
|
size_t pos = 0;
|
||||||
|
|
||||||
|
while ( pos < arg_str.length() )
|
||||||
|
{
|
||||||
|
if ( str[pos] == '\\' && str[pos+1] == 'x' &&
|
||||||
|
isxdigit(str[pos+2]) && isxdigit(str[pos+3]) )
|
||||||
|
{
|
||||||
|
*bufpos = (decode_hex(str[pos+2]) << 4) +
|
||||||
|
decode_hex(str[pos+3]);
|
||||||
|
|
||||||
|
pos += 4;
|
||||||
|
bufpos++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*bufpos++ = str[pos++];
|
||||||
|
}
|
||||||
|
|
||||||
|
*bufpos = 0;
|
||||||
|
string outstring(buf, bufpos - buf);
|
||||||
|
|
||||||
|
delete [] buf;
|
||||||
|
|
||||||
|
return outstring;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes a string, escapes characters into equivalent hex codes (\x##), and
|
* Takes a string, escapes characters into equivalent hex codes (\x##), and
|
||||||
* returns a string containing all escaped values.
|
* returns a string containing all escaped values.
|
||||||
|
@ -53,7 +91,7 @@
|
||||||
* @return A std::string containing a list of escaped hex values of the form
|
* @return A std::string containing a list of escaped hex values of the form
|
||||||
* \x## */
|
* \x## */
|
||||||
std::string get_escaped_string(const std::string& str, bool escape_all)
|
std::string get_escaped_string(const std::string& str, bool escape_all)
|
||||||
{
|
{
|
||||||
char tbuf[16];
|
char tbuf[16];
|
||||||
string esc = "";
|
string esc = "";
|
||||||
|
|
||||||
|
@ -71,7 +109,7 @@ std::string get_escaped_string(const std::string& str, bool escape_all)
|
||||||
}
|
}
|
||||||
|
|
||||||
return esc;
|
return esc;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* copy_string(const char* s)
|
char* copy_string(const char* s)
|
||||||
{
|
{
|
||||||
|
|
|
@ -90,6 +90,7 @@ void delete_each(T* t)
|
||||||
delete *it;
|
delete *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string get_unescaped_string(const std::string& str);
|
||||||
std::string get_escaped_string(const std::string& str, bool escape_all);
|
std::string get_escaped_string(const std::string& str, bool escape_all);
|
||||||
|
|
||||||
extern char* copy_string(const char* s);
|
extern char* copy_string(const char* s);
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
abc^J\xffdef
|
||||||
|
DATA2
|
||||||
|
abc|\xffdef
|
||||||
|
DATA2
|
||||||
|
abc\xff|def
|
||||||
|
DATA2
|
Loading…
Add table
Add a link
Reference in a new issue