Skip to content

Commit 2b5d5cc

Browse files
committed
[lldb][debugserver] Max response size for qSpeedTest (llvm#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 (cherry picked from commit ac8e7be)
1 parent ecea917 commit 2b5d5cc

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lldb/tools/debugserver/source/RNBRemote.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4519,12 +4519,12 @@ rnb_err_t RNBRemote::HandlePacket_qSpeedTest(const char *p) {
45194519
return HandlePacket_ILLFORMED(
45204520
__FILE__, __LINE__, p,
45214521
"Didn't find response_size value at right offset");
4522-
else if (*end == ';') {
4523-
static char g_data[4 * 1024 * 1024 + 16];
4524-
strcpy(g_data, "data:");
4525-
memset(g_data + 5, 'a', response_size);
4526-
g_data[response_size + 5] = '\0';
4527-
return SendPacket(g_data);
4522+
else if (*end == ';' && response_size < (4 * 1024 * 1024)) {
4523+
std::vector<char> buf(response_size + 6, 'a');
4524+
memcpy(buf.data(), "data:", 5);
4525+
buf[buf.size() - 1] = '\0';
4526+
rnb_err_t return_value = SendPacket(buf.data());
4527+
return return_value;
45284528
} else {
45294529
return SendErrorPacket("E79");
45304530
}

0 commit comments

Comments
 (0)