mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Bugfix for log writer.
It didn't escape binary stuff in some situations. Closes #585.
This commit is contained in:
parent
5e1ec1c50e
commit
83783c5ca7
10 changed files with 29 additions and 16 deletions
28
src/Desc.cc
28
src/Desc.cc
|
@ -232,35 +232,39 @@ static const char* find_first_unprintable(ODesc* d, const char* bytes, unsigned
|
|||
|
||||
void ODesc::AddBytes(const void* bytes, unsigned int n)
|
||||
{
|
||||
if ( ! escape )
|
||||
{
|
||||
AddBytesRaw(bytes, n);
|
||||
return;
|
||||
}
|
||||
|
||||
const char* s = (const char*) bytes;
|
||||
const char* e = (const char*) bytes + n;
|
||||
|
||||
while ( s < e )
|
||||
{
|
||||
const char* t1 = escape ? (const char*) memchr(s, escape[0], e - s) : e;
|
||||
const char* t2 = find_first_unprintable(this, s, t1 ? e - t1 : e - s);
|
||||
const char* t1 = (const char*) memchr(s, escape[0], e - s);
|
||||
|
||||
if ( t2 && (t2 < t1 || ! t1) )
|
||||
if ( ! t1 )
|
||||
t1 = e;
|
||||
|
||||
const char* t2 = find_first_unprintable(this, s, t1 - s);
|
||||
|
||||
if ( t2 && t2 < t1 )
|
||||
{
|
||||
AddBytesRaw(s, t2 - s);
|
||||
|
||||
char hex[6] = "\\x00";
|
||||
hex[2] = hex_chars[((*t2) & 0xf0) >> 4];
|
||||
hex[3] = hex_chars[(*t2) & 0x0f];
|
||||
AddBytesRaw(hex, sizeof(hex));
|
||||
AddBytesRaw(hex, 4);
|
||||
|
||||
s = t2 + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! escape )
|
||||
break;
|
||||
|
||||
if ( ! t1 )
|
||||
break;
|
||||
|
||||
if ( memcmp(t1, escape, escape_len) != 0 )
|
||||
break;
|
||||
break;
|
||||
|
||||
AddBytesRaw(s, t1 - s);
|
||||
|
||||
|
@ -269,7 +273,7 @@ void ODesc::AddBytes(const void* bytes, unsigned int n)
|
|||
char hex[5] = "\\x00";
|
||||
hex[2] = hex_chars[((*t1) & 0xf0) >> 4];
|
||||
hex[3] = hex_chars[(*t1) & 0x0f];
|
||||
AddBytesRaw(hex, sizeof(hex));
|
||||
AddBytesRaw(hex, 4);
|
||||
++t1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue