mirror of
https://github.com/wolfpld/tracy.git
synced 2026-11-20 06:35:59 +00:00
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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f2a4f2529e
commit
6fddfdbe22
@@ -811,6 +811,7 @@ static BroadcastMessage& GetBroadcastMessage( const char* procname, size_t pnsz,
|
||||
msg.listenPort = port;
|
||||
msg.pid = GetPid();
|
||||
|
||||
pnsz = std::min<size_t>( pnsz, WelcomeMessageProgramNameSize - 1 );
|
||||
memcpy( msg.programName, procname, pnsz );
|
||||
memset( msg.programName + pnsz, 0, WelcomeMessageProgramNameSize - pnsz );
|
||||
|
||||
|
||||
@@ -43,11 +43,12 @@ class NameBuffer {
|
||||
|
||||
BufferEntry add(const std::string& name) {
|
||||
std::lock_guard<std::mutex> 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]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user