14
15
#include "HcsVirtualMachine.h"
16
#include <format>
17
+#include <string>
18
+#include <string_view>
19
#include "hcs_schema.h"
20
#include "VirtioNetworking.h"
21
#include "NatNetworking.h"
32
constexpr auto SAVED_STATE_FILE_EXTENSION = L".vmrs";
33
constexpr auto SAVED_STATE_FILE_PREFIX = L"saved-state-";
34
35
+namespace {
36
+
37
+// Replace any character outside the conservative ASCII allowlist with '_' so the
38
+// result is safe to use as the HCS HostingProcessNameSuffix (which becomes the
39
+// vmmem-XXX process name visible in Task Manager and parsed by various tooling).
40
+std::wstring SanitizeHostingProcessNameSuffix(std::wstring_view name)
41
+{
42
+ constexpr std::wstring_view c_allowed = L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.";
43
+ std::wstring sanitized{name};
44
+ for (auto& c : sanitized)
45
+ {
46
+ if (c_allowed.find(c) == std::wstring_view::npos)
47
+ {
48
+ c = L'_';
49
+ }
50
+ }
51
+
52
+ return sanitized;
53
+}
54
+
55
+} // namespace
56
+
57
HcsVirtualMachine::HcsVirtualMachine(_In_ const WSLCSessionSettings* Settings)
58
{
59
THROW_HR_IF(E_POINTER, Settings == nullptr);
119
120
if (helpers::IsVmemmSuffixSupported() && Settings->DisplayName)
121
{
98
- vmSettings.ComputeTopology.Memory.HostingProcessNameSuffix = Settings->DisplayName;
122
+ // The vmmem-XXX process name shown in Task Manager (and parsed by tooling)
123
+ // can't tolerate spaces / unicode / etc., so sanitize before use. Note that
124
+ // Settings->DisplayName itself (e.g. the HCS Owner) is left untouched.
125
+ vmSettings.ComputeTopology.Memory.HostingProcessNameSuffix = SanitizeHostingProcessNameSuffix(Settings->DisplayName);
126
}
127
128
#ifdef _AMD64_