-
Notifications
You must be signed in to change notification settings - Fork 755
Fix XML escaping in GetManifestForRegisteredProvider #2351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
afb98b0
7780952
10a3cd6
7b04510
790ccd5
a0cfabe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| using FastSerialization; | ||
| using Microsoft.Diagnostics.Tracing.Compatibility; | ||
| using Microsoft.Diagnostics.Tracing.Session; | ||
| using Microsoft.Diagnostics.Utilities; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics; | ||
|
|
@@ -361,35 +362,35 @@ public static string GetManifestForRegisteredProvider(Guid providerGuid) | |
| { | ||
| StringWriter enumWriter = new StringWriter(); | ||
| string enumName = new string((char*)(&enumBuffer[enumInfo->NameOffset])); | ||
| enumAttrib = " map=\"" + enumName + "\""; | ||
| enumAttrib = " map=\"" + XmlUtilities.XmlEscape(enumName) + "\""; | ||
| if (enumInfo->Flag == MAP_FLAGS.EVENTMAP_INFO_FLAG_MANIFEST_VALUEMAP) | ||
| { | ||
| enumWriter.WriteLine(" <valueMap name=\"{0}\">", enumName); | ||
| enumWriter.WriteLine(" <valueMap name=\"{0}\">", XmlUtilities.XmlEscape(enumName)); | ||
| } | ||
| else | ||
| { | ||
| enumWriter.WriteLine(" <bitMap name=\"{0}\">", enumName); | ||
| enumWriter.WriteLine(" <bitMap name=\"{0}\">", XmlUtilities.XmlEscape(enumName)); | ||
| } | ||
|
|
||
| EVENT_MAP_ENTRY* mapEntries = &enumInfo->MapEntryArray; | ||
| for (int k = 0; k < enumInfo->EntryCount; k++) | ||
| { | ||
| int value = mapEntries[k].Value; | ||
| string valueName = new string((char*)(&enumBuffer[mapEntries[k].NameOffset])).Trim(); | ||
| enumWriter.WriteLine(" <map value=\"0x{0:x}\" message=\"$(string.map_{1}{2})\"/>", value, enumName, valueName); | ||
| string stringId = $"map_{enumName}{valueName}"; | ||
| string stringId = $"map_{MakeStringId(enumName)}{MakeStringId(valueName)}"; | ||
| enumWriter.WriteLine(" <map value=\"0x{0:x}\" message=\"$(string.{1})\"/>", value, stringId); | ||
| if (emittedStringIds.Add(stringId)) | ||
| { | ||
| enumLocalizations.WriteLine(" <string id=\"{0}\" value=\"{1}\"/>", stringId, valueName); | ||
| enumLocalizations.WriteLine(" <string id=\"{0}\" value=\"{1}\"/>", stringId, XmlUtilities.XmlEscape(valueName)); | ||
| } | ||
| } | ||
| if (enumInfo->Flag == MAP_FLAGS.EVENTMAP_INFO_FLAG_MANIFEST_VALUEMAP) | ||
| { | ||
| enumWriter.WriteLine(" </valueMap>", enumName); | ||
| enumWriter.WriteLine(" </valueMap>"); | ||
| } | ||
| else | ||
| { | ||
| enumWriter.WriteLine(" </bitMap>", enumName); | ||
| enumWriter.WriteLine(" </bitMap>"); | ||
| } | ||
|
|
||
| enumIntern[mapName] = enumWriter.ToString(); | ||
|
|
@@ -458,12 +459,12 @@ public static string GetManifestForRegisteredProvider(Guid providerGuid) | |
| manifest.WriteLine(" <keywords>"); | ||
| foreach (var keyValue in keywords) | ||
| { | ||
| manifest.WriteLine(" <keyword name=\"{0}\" message=\"$(string.keyword_{1})\" mask=\"0x{2:x}\"/>", | ||
| keyValue.Value, keyValue.Value, keyValue.Key); | ||
| string stringId = $"keyword_{keyValue.Value}"; | ||
| string stringId = $"keyword_{MakeStringId(keyValue.Value)}"; | ||
| manifest.WriteLine(" <keyword name=\"{0}\" message=\"$(string.{1})\" mask=\"0x{2:x}\"/>", | ||
| XmlUtilities.XmlEscape(keyValue.Value), stringId, keyValue.Key); | ||
| if (emittedStringIds.Add(stringId)) | ||
| { | ||
| localizedStrings.WriteLine(" <string id=\"{0}\" value=\"{1}\"/>", stringId, keyValue.Value); | ||
| localizedStrings.WriteLine(" <string id=\"{0}\" value=\"{1}\"/>", stringId, XmlUtilities.XmlEscape(keyValue.Value)); | ||
| } | ||
| } | ||
| manifest.WriteLine(" </keywords>"); | ||
|
|
@@ -473,25 +474,25 @@ public static string GetManifestForRegisteredProvider(Guid providerGuid) | |
| foreach (var taskValue in tasks.Keys) | ||
| { | ||
| var task = tasks[taskValue]; | ||
| manifest.WriteLine(" <task name=\"{0}\" message=\"$(string.task_{1})\" value=\"{2}\"{3}>", task.Name, task.Name, taskValue, | ||
| string taskStringId = $"task_{MakeStringId(task.Name)}"; | ||
| manifest.WriteLine(" <task name=\"{0}\" message=\"$(string.{1})\" value=\"{2}\"{3}>", XmlUtilities.XmlEscape(task.Name), taskStringId, taskValue, | ||
| task.Opcodes == null ? "/" : ""); // If no opcodes, terminate immediately. | ||
| string taskStringId = $"task_{task.Name}"; | ||
| if (emittedStringIds.Add(taskStringId)) | ||
| { | ||
| localizedStrings.WriteLine(" <string id=\"{0}\" value=\"{1}\"/>", taskStringId, task.Name); | ||
| localizedStrings.WriteLine(" <string id=\"{0}\" value=\"{1}\"/>", taskStringId, XmlUtilities.XmlEscape(task.Name)); | ||
| } | ||
| if (task.Opcodes != null) | ||
| { | ||
| manifest.WriteLine(">"); | ||
| manifest.WriteLine(" <opcodes>"); | ||
| foreach (var keyValue in task.Opcodes) | ||
| { | ||
| manifest.WriteLine(" <opcode name=\"{0}\" message=\"$(string.opcode_{1}{2})\" value=\"{3}\"/>", | ||
| keyValue.Value, task.Name, keyValue.Value, keyValue.Key); | ||
| string opcodeStringId = $"opcode_{task.Name}{keyValue.Value}"; | ||
| string opcodeStringId = $"opcode_{MakeStringId(task.Name)}{MakeStringId(keyValue.Value)}"; | ||
| manifest.WriteLine(" <opcode name=\"{0}\" message=\"$(string.{1})\" value=\"{2}\"/>", | ||
| XmlUtilities.XmlEscape(keyValue.Value), opcodeStringId, keyValue.Key); | ||
| if (emittedStringIds.Add(opcodeStringId)) | ||
| { | ||
| localizedStrings.WriteLine(" <string id=\"{0}\" value=\"{1}\"/>", opcodeStringId, keyValue.Value); | ||
| localizedStrings.WriteLine(" <string id=\"{0}\" value=\"{1}\"/>", opcodeStringId, XmlUtilities.XmlEscape(keyValue.Value)); | ||
| } | ||
| } | ||
| manifest.WriteLine(" </opcodes>"); | ||
|
|
@@ -572,6 +573,15 @@ private static string MakeLegalIdentifier(string name) | |
| return name; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a string ID suitable for use in XML manifest string tables. | ||
| /// XML-escapes the value to make it a valid XML attribute value. | ||
| /// </summary> | ||
| private static string MakeStringId(string value) | ||
|
||
| { | ||
| return XmlUtilities.XmlEscape(value); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Generates a space separated list of set of keywords 'keywordSet' using the table 'keywords' | ||
| /// It will generate new keyword names if needed and add them to 'keywords' if they are not present. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concatenate enumName and valueName first, then call MakeStringId on the result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to concatenate strings before calling XmlUtilities.XmlEscape in commit a0cfabe.