Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit fc18c3d

Browse files
author
John Salem
authored
Account for quoted values in provider filter string (#26159) (#26195)
* Account for quoted values in provider filter string
1 parent d662cf1 commit fc18c3d

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/vm/eventpipeprovider.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,17 +225,33 @@ void EventPipeProvider::AddEvent(EventPipeEvent &event)
225225
// of pairs of null terminated strings. The first member of the pair is
226226
// the key and the second is the value.
227227
// To convert to this format we need to convert all '=' and ';'
228-
// characters to '\0'.
228+
// characters to '\0', except when in a quoted string.
229229
SString dstBuffer;
230230
SString(pFilterData).ConvertToUTF8(dstBuffer);
231231

232232
const COUNT_T BUFFER_SIZE = dstBuffer.GetCount() + 1;
233233
buffer.AllocThrows(BUFFER_SIZE);
234+
BOOL isQuotedValue = false;
235+
COUNT_T j = 0;
234236
for (COUNT_T i = 0; i < BUFFER_SIZE; ++i)
235-
buffer[i] = (dstBuffer[i] == '=' || dstBuffer[i] == ';') ? '\0' : dstBuffer[i];
237+
{
238+
// if a value is a quoted string, leave the quotes out from the destination
239+
// and don't replace `=` or `;` characters until leaving the quoted section
240+
// e.g., key="a;value=";foo=bar --> { key\0a;value=\0foo\0bar\0 }
241+
if (dstBuffer[i] == '"')
242+
{
243+
isQuotedValue = !isQuotedValue;
244+
continue;
245+
}
246+
buffer[j++] = ((dstBuffer[i] == '=' || dstBuffer[i] == ';') && !isQuotedValue) ? '\0' : dstBuffer[i];
247+
}
248+
249+
// In case we skipped over quotes in the filter string, shrink the buffer size accordingly
250+
if (j < dstBuffer.GetCount())
251+
buffer.Shrink(j + 1);
236252

237253
eventFilterDescriptor.Ptr = reinterpret_cast<ULONGLONG>(buffer.Ptr());
238-
eventFilterDescriptor.Size = static_cast<ULONG>(BUFFER_SIZE);
254+
eventFilterDescriptor.Size = static_cast<ULONG>(buffer.Size());
239255
eventFilterDescriptor.Type = 0; // EventProvider.cs: `internal enum ControllerCommand.Update`
240256
isEventFilterDescriptorInitialized = true;
241257
}

0 commit comments

Comments
 (0)