From 1dfe7878f6b7cecf3a6d955efca2927f93e0e1bb Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 28 Jun 2023 16:57:03 +0200 Subject: [PATCH] [proxy,module] always check path exists for dyn-channel-dump --- .../dyn-channel-dump/dyn-channel-dump.cpp | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/server/proxy/modules/dyn-channel-dump/dyn-channel-dump.cpp b/server/proxy/modules/dyn-channel-dump/dyn-channel-dump.cpp index 9b19c5453..50adae96c 100644 --- a/server/proxy/modules/dyn-channel-dump/dyn-channel-dump.cpp +++ b/server/proxy/modules/dyn-channel-dump/dyn-channel-dump.cpp @@ -120,20 +120,8 @@ class ChannelData return enabled; } - std::filesystem::path filepath(const std::string& channel, bool back, uint64_t count) const + bool ensure_path_exists() { - auto name = idstr(channel, back); - char cstr[32] = {}; - _snprintf(cstr, sizeof(cstr), "%016" PRIx64 "-", count); - auto path = _base / cstr; - path += name; - path += ".dump"; - return path; - } - - bool create() - { - if (!std::filesystem::exists(_base)) { if (!std::filesystem::create_directories(_base)) @@ -147,6 +135,13 @@ class ChannelData WLog_ERR(TAG, "dump path %s is not a directory", _base.c_str()); return false; } + return true; + } + + bool create() + { + if (!ensure_path_exists()) + return false; if (_channels_to_dump.empty()) { @@ -163,6 +158,17 @@ class ChannelData } private: + std::filesystem::path filepath(const std::string& channel, bool back, uint64_t count) const + { + auto name = idstr(channel, back); + char cstr[32] = {}; + _snprintf(cstr, sizeof(cstr), "%016" PRIx64 "-", count); + auto path = _base / cstr; + path += name; + path += ".dump"; + return path; + } + std::string idstr(const std::string& name, bool back) const { std::stringstream ss; @@ -302,6 +308,9 @@ static BOOL dump_dyn_channel_intercept(proxyPlugin* plugin, proxyData* pdata, vo return FALSE; } + if (!cdata->ensure_path_exists()) + return FALSE; + auto stream = cdata->stream(data->name, data->isBackData); auto buffer = reinterpret_cast(Stream_ConstBuffer(data->data)); if (!stream.is_open() || !stream.good())