mirror of https://github.com/microsoft/WSL
WSLA: Add null validation for CreateContainer Image and Name fields (#13917)
* WSLA: Add null validation for CreateContainer Image and Name fields * adjust comment --------- Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
This commit is contained in:
parent
fbe44506ae
commit
d4ce4e9c5c
|
|
@ -316,6 +316,10 @@ try
|
|||
{
|
||||
RETURN_HR_IF_NULL(E_POINTER, containerOptions);
|
||||
|
||||
// Validate that Image and Name are not null.
|
||||
RETURN_HR_IF(E_INVALIDARG, containerOptions->Image == nullptr);
|
||||
RETURN_HR_IF(E_INVALIDARG, containerOptions->Name == nullptr);
|
||||
|
||||
std::lock_guard lock{m_lock};
|
||||
RETURN_HR_IF(HRESULT_FROM_WIN32(ERROR_INVALID_STATE), !m_virtualMachine);
|
||||
|
||||
|
|
|
|||
|
|
@ -1231,6 +1231,32 @@ class WSLATests
|
|||
auto [hresult, container] = launcher.LaunchNoThrow(*session);
|
||||
VERIFY_ARE_EQUAL(hresult, E_FAIL); // TODO: Have a nicer error code when the image is not found.
|
||||
}
|
||||
|
||||
// Test null image name
|
||||
{
|
||||
WSLA_CONTAINER_OPTIONS options{};
|
||||
options.Image = nullptr;
|
||||
options.Name = "test-container";
|
||||
options.InitProcessOptions.CommandLine = nullptr;
|
||||
options.InitProcessOptions.CommandLineCount = 0;
|
||||
|
||||
wil::com_ptr<IWSLAContainer> container;
|
||||
auto hr = session->CreateContainer(&options, &container);
|
||||
VERIFY_ARE_EQUAL(hr, E_INVALIDARG);
|
||||
}
|
||||
|
||||
// Test null container name
|
||||
{
|
||||
WSLA_CONTAINER_OPTIONS options{};
|
||||
options.Image = "debian:latest";
|
||||
options.Name = nullptr;
|
||||
options.InitProcessOptions.CommandLine = nullptr;
|
||||
options.InitProcessOptions.CommandLineCount = 0;
|
||||
|
||||
wil::com_ptr<IWSLAContainer> container;
|
||||
auto hr = session->CreateContainer(&options, &container);
|
||||
VERIFY_ARE_EQUAL(hr, E_INVALIDARG);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(ContainerState)
|
||||
|
|
|
|||
Loading…
Reference in New Issue