Check buffer out and size in HID_USBv5/USB_VEN GetVersion Ioctl

This commit is contained in:
y21 2025-05-01 23:55:29 +02:00
parent 2e22a3cf42
commit f665eaad5f
4 changed files with 19 additions and 14 deletions

View File

@ -204,6 +204,22 @@ std::optional<IPCReply> USBV5ResourceManager::HandleDeviceIOCtl(const IOCtlReque
return handler(*device);
}
IPCReply USBV5ResourceManager::GetUSBVersion(const IOCtlRequest& request) const
{
static constexpr u32 VERSION = 0x50001;
if (request.buffer_in != 0 || request.buffer_in_size != 0 || request.buffer_out == 0 ||
request.buffer_out_size != 0x20)
{
return IPCReply(IPC_EINVAL);
}
auto& system = GetSystem();
auto& memory = system.GetMemory();
memory.Write_U32(VERSION, request.buffer_out);
return IPCReply(IPC_SUCCESS);
}
void USBV5ResourceManager::OnDeviceChange(const ChangeEvent event,
std::shared_ptr<USB::Device> device)
{

View File

@ -83,6 +83,7 @@ protected:
using Handler = std::function<std::optional<IPCReply>(USBV5Device&)>;
std::optional<IPCReply> HandleDeviceIOCtl(const IOCtlRequest& request, Handler handler);
IPCReply GetUSBVersion(const IOCtlRequest& request) const;
void OnDeviceChange(ChangeEvent event, std::shared_ptr<USB::Device> device) override;
void OnDeviceChangeEnd() override;

View File

@ -16,21 +16,15 @@
namespace IOS::HLE
{
constexpr u32 USBV5_VERSION = 0x50001;
USB_HIDv5::~USB_HIDv5() = default;
std::optional<IPCReply> USB_HIDv5::IOCtl(const IOCtlRequest& request)
{
auto& system = GetSystem();
auto& memory = system.GetMemory();
request.Log(GetDeviceName(), Common::Log::LogType::IOS_USB);
switch (request.request)
{
case USB::IOCTL_USBV5_GETVERSION:
memory.Write_U32(USBV5_VERSION, request.buffer_out);
return IPCReply(IPC_SUCCESS);
return GetUSBVersion(request);
case USB::IOCTL_USBV5_GETDEVICECHANGE:
return GetDeviceChange(request);
case USB::IOCTL_USBV5_SHUTDOWN:

View File

@ -16,21 +16,15 @@
namespace IOS::HLE
{
constexpr u32 USBV5_VERSION = 0x50001;
USB_VEN::~USB_VEN() = default;
std::optional<IPCReply> USB_VEN::IOCtl(const IOCtlRequest& request)
{
auto& system = GetSystem();
auto& memory = system.GetMemory();
request.Log(GetDeviceName(), Common::Log::LogType::IOS_USB);
switch (request.request)
{
case USB::IOCTL_USBV5_GETVERSION:
memory.Write_U32(USBV5_VERSION, request.buffer_out);
return IPCReply(IPC_SUCCESS);
return GetUSBVersion(request);
case USB::IOCTL_USBV5_GETDEVICECHANGE:
return GetDeviceChange(request);
case USB::IOCTL_USBV5_SHUTDOWN: