Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/linux/init/plan9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ wil::unique_fd CreateUnixServerSocket(const char* path)
}
});

// Check if the path will fit in a sockaddr_un.
// Check if the path will fit in a sockaddr_un (with room for null terminator).
std::string_view pathView{path};
if (pathView.length() > sizeof(sockaddr_un::sun_path))
if (pathView.length() >= sizeof(sockaddr_un::sun_path))
{
// It won't, so split the parent path and child name.
auto index = pathView.find_last_of('/');
Expand All @@ -64,6 +64,9 @@ wil::unique_fd CreateUnixServerSocket(const char* path)
const std::string parent{pathView.substr(0, index)};
pathView = pathView.substr(index + 1);

// Ensure the child name fits in sun_path (with null terminator).
THROW_ERRNO_IF(ENAMETOOLONG, pathView.length() >= sizeof(sockaddr_un::sun_path));

// Get the current working directory to restore it later, and change to the socket's parent
// path.
oldCwd = getcwd(oldCwdBuffer, sizeof(oldCwdBuffer));
Expand Down
4 changes: 2 additions & 2 deletions src/windows/service/exe/LxssHttpProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,12 @@ try
if (openBracket != ::std::wstring::npos)
{
const auto closeBracket = portRemoved.find_first_of(L"]");
if (closeBracket == ::std::wstring::npos || (openBracket + 1 >= closeBracket - 1))
if (closeBracket == ::std::wstring::npos || (openBracket + 1 >= closeBracket))
{
// no other of below checks can contain brackets
return UnsupportedProxyReason::Supported;
}
portRemoved = portRemoved.substr(openBracket + 1, closeBracket - 1);
portRemoved = portRemoved.substr(openBracket + 1, closeBracket - openBracket - 1);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish there was an easy way to add test coverage for this.

If we ever factor IsUnsupportedProxy() in common I guess we could add coverage for this

}

in6_addr addrV6{};
Expand Down
14 changes: 9 additions & 5 deletions src/windows/service/exe/LxssUserSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1737,11 +1737,15 @@ try
RETURN_HR_IF(WSL_E_DISTRO_NOT_STOPPED, m_runningInstances.contains(*DistroGuid));

const wil::unique_hfile vhd{::CreateFileW(configuration.VhdFilePath.c_str(), GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr)};
if (const DWORD err = GetLastError(); err == ERROR_SHARING_VIOLATION)
if (!vhd)
{
THROW_HR_WITH_USER_ERROR(HRESULT_FROM_WIN32(err), wsl::shared::Localization::MessageVhdInUse());
const DWORD err = GetLastError();
if (err == ERROR_SHARING_VIOLATION)
{
THROW_HR_WITH_USER_ERROR(HRESULT_FROM_WIN32(err), wsl::shared::Localization::MessageVhdInUse());
}
THROW_WIN32(err);
}
THROW_LAST_ERROR_IF(!vhd);

FILE_SET_SPARSE_BUFFER buffer{
.SetSparse = Sparse,
Expand Down Expand Up @@ -1949,7 +1953,7 @@ HRESULT LxssUserSessionImpl::SetVersion(_In_ LPCGUID DistroGuid, _In_ ULONG Vers
auto wsl1Pipe = wsl::windows::common::wslutil::OpenAnonymousPipe(LX_RELAY_BUFFER_SIZE, true, true);

wsl::windows::common::relay::ScopedMultiRelay stdErrRelay(
std::vector<HANDLE>{wsl1Pipe.first.get(), reinterpret_cast<HANDLE*>(vmContext.errorSocket.get())}, onTarOutput);
std::vector<HANDLE>{wsl1Pipe.first.get(), reinterpret_cast<HANDLE>(vmContext.errorSocket.get())}, onTarOutput);

// Add mounts for the rootfs and tools.
auto mounts = _CreateSetupMounts(configuration);
Expand Down Expand Up @@ -2014,7 +2018,7 @@ HRESULT LxssUserSessionImpl::SetVersion(_In_ LPCGUID DistroGuid, _In_ ULONG Vers
auto wsl1Pipe = wsl::windows::common::wslutil::OpenAnonymousPipe(LX_RELAY_BUFFER_SIZE, true, true);

wsl::windows::common::relay::ScopedMultiRelay stdErrRelay(
std::vector<HANDLE>{wsl1Pipe.first.get(), reinterpret_cast<HANDLE*>(vmContext.errorSocket.get())}, onTarOutput);
std::vector<HANDLE>{wsl1Pipe.first.get(), reinterpret_cast<HANDLE>(vmContext.errorSocket.get())}, onTarOutput);

// Add mounts for the rootfs and tools.
auto mounts = _CreateSetupMounts(configuration);
Expand Down