Skip to content

Commit ac8e7be

Browse files
authored
[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
1 parent 6aebbb0 commit ac8e7be

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
@@ -4423,12 +4423,12 @@ rnb_err_t RNBRemote::HandlePacket_qSpeedTest(const char *p) {
44234423
return HandlePacket_ILLFORMED(
44244424
__FILE__, __LINE__, p,
44254425
"Didn't find response_size value at right offset");
4426-
else if (*end == ';') {
4427-
static char g_data[4 * 1024 * 1024 + 16];
4428-
strcpy(g_data, "data:");
4429-
memset(g_data + 5, 'a', response_size);
4430-
g_data[response_size + 5] = '\0';
4431-
return SendPacket(g_data);
4426+
else if (*end == ';' && response_size < (4 * 1024 * 1024)) {
4427+
std::vector<char> buf(response_size + 6, 'a');
4428+
memcpy(buf.data(), "data:", 5);
4429+
buf[buf.size() - 1] = '\0';
4430+
rnb_err_t return_value = SendPacket(buf.data());
4431+
return return_value;
44324432
} else {
44334433
return SendErrorPacket("E79");
44344434
}

0 commit comments

Comments
 (0)