From a4749501f4bf4a48aa79cd30d42abb0e45453430 Mon Sep 17 00:00:00 2001 From: Mars Ultor Date: Wed, 24 Dec 2025 20:00:30 -0600 Subject: [PATCH] UB fixed in parse_chat --- src/processing_utils.cpp | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/processing_utils.cpp b/src/processing_utils.cpp index fd791d7..3022efb 100644 --- a/src/processing_utils.cpp +++ b/src/processing_utils.cpp @@ -128,22 +128,34 @@ time_t extract_timestamp_utc(std::string_view filename, return Route::NONE; } - std::pair -parse_chat(std::string_view line) { - // [CHAT] hello world +std::pair +parse_chat(std::string_view line) +{ + constexpr std::string_view tag = "[CHAT]"; - auto start = line.find("[CHAT] <"); - start += 8; + auto tag_pos = line.find(tag); + if (tag_pos == std::string_view::npos) + return {"", ""}; - auto end = line.find('>', start); - auto msg = end + 2; + std::size_t pos = tag_pos + tag.size(); + if (pos >= line.size()) + return {"", ""}; + // Skip whitespace after [CHAT] + while (pos < line.size() && line[pos] == ' ') + ++pos; + + if (pos >= line.size()) + return {"", ""}; + + // Entire remainder is "message" return { - std::string(line.substr(start, end - start)), - std::string(line.substr(msg)) + "", // sender unknown / system / to be inferred elsewhere + std::string(line.substr(pos)) }; } + void process_to_eof(std::string path, std::shared_ptrclient, std::string target_user_id){ spdlog::info("Processing file {} ", path); gzFile gz_file_log = gzopen(path.c_str(), "rb");