Fix batch of minor issues (#40818)
* Fix potential uint16_t counter overflow to 0 * Fix typo in string resize * fix wrong buffer size for wcscpy_s * update file level comments * make address family comparison more clear * avoid out of bound read
Feng Wang committed
Jun 18, 2026 at 10:54 UTC
c8a67e7a6ede2d39b02effed2e8f4fbd29bfea47
5 files changed
+12
-10
src/windows/common/filesystem.cpp
+1
-1
@@ -816,7 +816,7 @@ std::pair<std::string, std::string> wsl::windows::common::filesystem::GetHostAnd
816
}
817
else
818
{
819
- domainName.resize(size - 1, L'\0');
819
+ domainName.resize(size - 1, '\0');
820
THROW_LAST_ERROR_IF(!GetComputerNameExA(ComputerNameDnsDomain, domainName.data(), &size));
821
WI_ASSERT(domainName.size() == size);
822
src/windows/service/exe/LxssUserSession.cpp
+1
-1
@@ -1043,7 +1043,7 @@ HRESULT LxssUserSessionImpl::EnumerateDistributions(_Out_ PULONG DistributionCou
1043
static_assert((RTL_NUMBER_OF(current->DistroName) - 1) == LX_INIT_DISTRO_NAME_MAX);
1044
1045
memset(current->DistroName, 0, sizeof(current->DistroName));
1046
- wcscpy_s(current->DistroName, RTL_NUMBER_OF(current->DistroName) - 1, configuration.Name.c_str());
1046
+ wcscpy_s(current->DistroName, RTL_NUMBER_OF(current->DistroName), configuration.Name.c_str());
1047
}
1048
1049
*DistributionCount = numberOfDistributions;
src/windows/wslc/tasks/SessionTasks.h
+2
-2
@@ -4,11 +4,11 @@ Copyright (c) Microsoft. All rights reserved.
4
5
Module Name:
6
7
- DiagTasks.h
7
+ SessionTasks.h
8
9
Abstract:
10
11
- Declaration of diag command execution tasks.
11
+ Declaration of session command execution tasks.
12
13
--*/
14
#pragma once
src/windows/wslcsession/DockerEventTracker.cpp
+2
-1
@@ -74,7 +74,8 @@ DockerEventTracker::DockerEventTracker(DockerHTTPClient& dockerClient, WSLCSessi
74
{
75
WSL_LOG(
76
"DockerEventParseError",
77
- TraceLoggingValue(buffer.data(), "Data"),
77
+ TraceLoggingCountedString(
78
+ buffer.data(), static_cast<UINT16>(std::min(buffer.size(), static_cast<size_t>(USHRT_MAX))), "Data"),
79
TraceLoggingValue(wil::ResultFromCaughtException(), "Error"),
80
TraceLoggingValue(m_session.Id(), "SessionId"));
81
}
src/windows/wslcsession/WSLCVirtualMachine.cpp
+6
-5
@@ -157,7 +157,7 @@ void VMPortMapping::Release()
157
158
bool VMPortMapping::IsLocalhost() const
159
{
160
- if (BindAddress.Ipv4.sin_family == AF_INET6)
160
+ if (BindAddress.si_family == AF_INET6)
161
{
162
return IN6_IS_ADDR_LOOPBACK(&BindAddress.Ipv6.sin6_addr);
163
}
@@ -1210,12 +1210,13 @@ std::shared_ptr<VmPortAllocation> WSLCVirtualMachine::AllocatePort(int Family, i
1210
{
1211
std::lock_guard lock{m_lock};
1212
1213
- for (auto i = CONTAINER_PORT_RANGE.first; i <= CONTAINER_PORT_RANGE.second; i++)
1213
+ for (uint32_t i = CONTAINER_PORT_RANGE.first; i <= CONTAINER_PORT_RANGE.second; i++)
1214
{
1215
- if (!m_allocatedPorts.contains(i))
1215
+ uint16_t port = static_cast<uint16_t>(i);
1216
+ if (!m_allocatedPorts.contains(port))
1217
{
1217
- WI_VERIFY(m_allocatedPorts.insert(i).second);
1218
- return std::make_shared<VmPortAllocation>(i, Family, Protocol, *this);
1218
+ WI_VERIFY(m_allocatedPorts.insert(port).second);
1219
+ return std::make_shared<VmPortAllocation>(port, Family, Protocol, *this);
1220
}
1221
}
1222