dmnt.gen2: sanitize brackets in thread names to be valid xml

This commit is contained in:
Michael Scire 2022-06-07 22:03:37 -07:00
parent 36bdb83cfc
commit 114d2598da

View file

@ -2353,8 +2353,33 @@ namespace ams::dmnt {
m_debug_process.GetThreadName(name, thread_ids[i]); m_debug_process.GetThreadName(name, thread_ids[i]);
name[sizeof(name) - 1] = '\x00'; name[sizeof(name) - 1] = '\x00';
/* Sanitize the thread name. */
char sanitized[os::ThreadNameLengthMax * 4 + 1];
{
char *cur = sanitized;
for (size_t i = 0; i < util::size(name); ++i) {
if (name[i] == '<') {
*(cur++) = '&';
*(cur++) = 'l';
*(cur++) = 't';
*(cur++) = ';';
} else if (name[i] == '>') {
*(cur++) = '&';
*(cur++) = 'r';
*(cur++) = 't';
*(cur++) = ';';
} else {
*(cur++) = name[i];
}
if (name[i] == '\x00') {
break;
}
}
}
/* Set the thread entry */ /* Set the thread entry */
AppendReplyFormat(dst_cur, dst_end, "<thread id=\"p%lx.%lx\" core=\"%u\" name=\"%s\" />", m_process_id.value, thread_ids[i], core, name); AppendReplyFormat(dst_cur, dst_end, "<thread id=\"p%lx.%lx\" core=\"%u\" name=\"%s\" />", m_process_id.value, thread_ids[i], core, sanitized);
} }
} }