From 114d2598da70582c62831c4d939042ddc953e04f Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 7 Jun 2022 22:03:37 -0700 Subject: [PATCH] dmnt.gen2: sanitize brackets in thread names to be valid xml --- .../source/dmnt2_gdb_server_impl.cpp | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/stratosphere/dmnt.gen2/source/dmnt2_gdb_server_impl.cpp b/stratosphere/dmnt.gen2/source/dmnt2_gdb_server_impl.cpp index 810e2635c..ef6ef50d2 100644 --- a/stratosphere/dmnt.gen2/source/dmnt2_gdb_server_impl.cpp +++ b/stratosphere/dmnt.gen2/source/dmnt2_gdb_server_impl.cpp @@ -2353,8 +2353,33 @@ namespace ams::dmnt { m_debug_process.GetThreadName(name, thread_ids[i]); 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 */ - AppendReplyFormat(dst_cur, dst_end, "", m_process_id.value, thread_ids[i], core, name); + AppendReplyFormat(dst_cur, dst_end, "", m_process_id.value, thread_ids[i], core, sanitized); } }