[Lldb-commits] [lldb] [lldb][debugserver] Max response size for qSpeedTest (PR #156099)
Jason Molenda via lldb-commits
lldb-commits at lists.llvm.org
Fri Aug 29 13:28:49 PDT 2025
https://github.com/jasonmolenda created https://github.com/llvm/llvm-project/pull/156099
The qSpeedTest packet is used for experiments to determine the optimal packet size for a given communication medium, e.g. to transfer 10MB of memory, is it faster to send a hundred 100KB packets or ten 1MB packets. It creates a packet of the requested size in a stack allocation, but is not checking that its buffer is large enough for the requested size.
Change this allocation to be on heap, and impose a maximum size that can be tested (4MB, for now).
rdar://158630250
>From e827cffbf7318c1023277e780f30deb80d965d81 Mon Sep 17 00:00:00 2001
From: Jason Molenda <jmolenda at apple.com>
Date: Fri, 29 Aug 2025 13:21:57 -0700
Subject: [PATCH] [lldb][debugserver] Max response size for qSpeedTest
Only allow qSpeedTest packet size requests up to 4MB.
Allocate the temporary buffer for the packet on the
heap, instead of stack.
rdar://158630250
---
lldb/tools/debugserver/source/RNBRemote.cpp | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/lldb/tools/debugserver/source/RNBRemote.cpp b/lldb/tools/debugserver/source/RNBRemote.cpp
index 102b2ab3e8484..d9fb22c6a1c06 100644
--- a/lldb/tools/debugserver/source/RNBRemote.cpp
+++ b/lldb/tools/debugserver/source/RNBRemote.cpp
@@ -4423,12 +4423,12 @@ rnb_err_t RNBRemote::HandlePacket_qSpeedTest(const char *p) {
return HandlePacket_ILLFORMED(
__FILE__, __LINE__, p,
"Didn't find response_size value at right offset");
- else if (*end == ';') {
- static char g_data[4 * 1024 * 1024 + 16];
- strcpy(g_data, "data:");
- memset(g_data + 5, 'a', response_size);
- g_data[response_size + 5] = '\0';
- return SendPacket(g_data);
+ else if (*end == ';' && response_size < (4 * 1024 * 1024)) {
+ std::vector<char> buf(response_size + 6, 'a');
+ memcpy(buf.data(), "data:", 5);
+ buf[buf.size() - 1] = '\0';
+ rnb_err_t return_value = SendPacket(buf.data());
+ return return_value;
} else {
return SendErrorPacket("E79");
}
More information about the lldb-commits
mailing list