From 6fddfdbe225cf5f1cad335cc31d8765328f8b4fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Gr=C3=A9goire?= Date: Mon, 9 Nov 2026 18:02:30 +0100 Subject: [PATCH] Client: don't overflow the broadcast program name GetBroadcastMessage is given strlen(m_programName), which can exceed WelcomeMessageProgramNameSize when the program name is set with a long string (e.g. by the Python bindings). Clamp the length inside GetBroadcastMessage, which owns the fixed-size buffer. Also null-terminate names stored in the Python NameBuffer and reject names that leave no room for the terminator. Co-Authored-By: Claude Opus 5.5 --- public/client/TracyProfiler.cpp | 1 + python/bindings/NameBuffer.hpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/public/client/TracyProfiler.cpp b/public/client/TracyProfiler.cpp index 64bf8965..81a5e4c5 100644 --- a/public/client/TracyProfiler.cpp +++ b/public/client/TracyProfiler.cpp @@ -811,6 +811,7 @@ static BroadcastMessage& GetBroadcastMessage( const char* procname, size_t pnsz, msg.listenPort = port; msg.pid = GetPid(); + pnsz = std::min( pnsz, WelcomeMessageProgramNameSize - 1 ); memcpy( msg.programName, procname, pnsz ); memset( msg.programName + pnsz, 0, WelcomeMessageProgramNameSize - pnsz ); diff --git a/python/bindings/NameBuffer.hpp b/python/bindings/NameBuffer.hpp index 071010e5..90e7ccee 100644 --- a/python/bindings/NameBuffer.hpp +++ b/python/bindings/NameBuffer.hpp @@ -43,11 +43,12 @@ class NameBuffer { BufferEntry add(const std::string& name) { std::lock_guard lock(m_mutex); - if (m_index >= BUFFER_SIZE || name.size() > NAME_LENGTH) + if (m_index >= BUFFER_SIZE || name.size() >= NAME_LENGTH) return std::make_pair(std::nullopt, nullptr); auto index = m_index++; name.copy(m_buffer[index], name.size()); + m_buffer[index][name.size()] = '\0'; return std::make_pair(index, m_buffer[index]); }