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:
Ben Hillis 2025-12-15 14:04:45 -08:00 committed by GitHub
parent fbe44506ae
commit d4ce4e9c5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 0 deletions

View File

@ -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);

View File

@ -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)