From 05b10fe2e78d40f827a34fc932fce7be6d1c7daa Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 15 Aug 2018 18:01:56 -0500 Subject: [PATCH] BIT-1544: allow NULs in file analysis handles --- CHANGES | 4 ++++ VERSION | 2 +- src/file_analysis/Manager.cc | 11 ++++++++++- src/file_analysis/Manager.h | 6 ++++-- src/file_analysis/file_analysis.bif | 4 +++- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index af9f1b88f5..b088383e2c 100644 --- a/CHANGES +++ b/CHANGES @@ -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 * Fix seg fault on trying to type-cast invalid/nil Broker::Data diff --git a/VERSION b/VERSION index 4744b3cd09..e13a35390e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.5-842 +2.5-843 diff --git a/src/file_analysis/Manager.cc b/src/file_analysis/Manager.cc index 177f5446dd..b095315de8 100644 --- a/src/file_analysis/Manager.cc +++ b/src/file_analysis/Manager.cc @@ -104,7 +104,16 @@ void Manager::SetHandle(const string& handle) if ( handle.empty() ) 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); } diff --git a/src/file_analysis/Manager.h b/src/file_analysis/Manager.h index b6d3658f9e..fe3328b679 100644 --- a/src/file_analysis/Manager.h +++ b/src/file_analysis/Manager.h @@ -70,7 +70,8 @@ public: /** * 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. */ string HashHandle(const string& handle) const; @@ -78,7 +79,8 @@ public: /** * Take in a unique file handle string to identify next piece of * 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); diff --git a/src/file_analysis/file_analysis.bif b/src/file_analysis/file_analysis.bif index f445a9cf6a..d2c6c43394 100644 --- a/src/file_analysis/file_analysis.bif +++ b/src/file_analysis/file_analysis.bif @@ -105,7 +105,9 @@ module GLOBAL; ## .. bro:see:: get_file_handle function set_file_handle%(handle: string%): any %{ - file_mgr->SetHandle(handle->CheckString()); + auto bytes = reinterpret_cast(handle->Bytes()); + auto h = std::string(bytes, handle->Len()); + file_mgr->SetHandle(h); return 0; %}