BIT-1544: allow NULs in file analysis handles

This commit is contained in:
Jon Siwek 2018-08-15 18:01:56 -05:00
parent f336c8c710
commit 05b10fe2e7
5 changed files with 22 additions and 5 deletions

View file

@ -1,4 +1,8 @@
2.5-843 | 2018-08-15 18:01:56 -0500
* BIT-1544: allow NULs in file analysis handles (Jon Siwek, Corelight)
2.5-842 | 2018-08-15 11:00:20 -0500 2.5-842 | 2018-08-15 11:00:20 -0500
* Fix seg fault on trying to type-cast invalid/nil Broker::Data * Fix seg fault on trying to type-cast invalid/nil Broker::Data

View file

@ -1 +1 @@
2.5-842 2.5-843

View file

@ -104,7 +104,16 @@ void Manager::SetHandle(const string& handle)
if ( handle.empty() ) if ( handle.empty() )
return; return;
DBG_LOG(DBG_FILE_ANALYSIS, "Set current handle to %s", handle.c_str()); #ifdef DEBUG
if ( debug_logger.IsEnabled(DBG_FILE_ANALYSIS) )
{
BroString tmp{handle};
auto rendered = tmp.Render();
DBG_LOG(DBG_FILE_ANALYSIS, "Set current handle to %s", rendered);
delete [] rendered;
}
#endif
current_file_id = HashHandle(handle); current_file_id = HashHandle(handle);
} }

View file

@ -70,7 +70,8 @@ public:
/** /**
* Creates a file identifier from a unique file handle string. * Creates a file identifier from a unique file handle string.
* @param handle a unique string which identifies a single file. * @param handle a unique string (may contain NULs) which identifies
* a single file.
* @return a prettified MD5 hash of \a handle, truncated to *bits_per_uid* bits. * @return a prettified MD5 hash of \a handle, truncated to *bits_per_uid* bits.
*/ */
string HashHandle(const string& handle) const; string HashHandle(const string& handle) const;
@ -78,7 +79,8 @@ public:
/** /**
* Take in a unique file handle string to identify next piece of * Take in a unique file handle string to identify next piece of
* incoming file data/information. * incoming file data/information.
* @param handle a unique string which identifies a single file. * @param handle a unique string (may contain NULs) which identifies
* a single file.
*/ */
void SetHandle(const string& handle); void SetHandle(const string& handle);

View file

@ -105,7 +105,9 @@ module GLOBAL;
## .. bro:see:: get_file_handle ## .. bro:see:: get_file_handle
function set_file_handle%(handle: string%): any function set_file_handle%(handle: string%): any
%{ %{
file_mgr->SetHandle(handle->CheckString()); auto bytes = reinterpret_cast<const char*>(handle->Bytes());
auto h = std::string(bytes, handle->Len());
file_mgr->SetHandle(h);
return 0; return 0;
%} %}