From 48d30d139acfdaf0825beee5e9a59bf3f9852a28 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 3 Nov 2026 08:18:17 -0800
Subject: [PATCH] Allow SPI reads of larger size than requested in the HIDAPI
Nintendo Switch driver
We just need to validate that the result is the right address and at least as long as we expected.
Fixes https://github.com/libsdl-org/SDL/issues/16434
---
src/joystick/hidapi/SDL_hidapi_switch.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/joystick/hidapi/SDL_hidapi_switch.c b/src/joystick/hidapi/SDL_hidapi_switch.c
index 21f3a6559ba78..81f6a53310540 100644
--- a/src/joystick/hidapi/SDL_hidapi_switch.c
+++ b/src/joystick/hidapi/SDL_hidapi_switch.c
@@ -425,8 +425,10 @@ static SwitchSubcommandInputPacket_t *ReadSubcommandReply(SDL_DriverSwitch_Conte
continue;
}
if (reply->ucSubcommandID == k_eSwitchSubcommandIDs_SPIFlashRead) {
- SDL_assert(ucLen == sizeof(reply->spiReadData.opData));
- if (SDL_memcmp(&reply->spiReadData.opData, pBuf, ucLen) != 0) {
+ SDL_assert(ucLen == sizeof(SwitchSPIOpData_t));
+ const SwitchSPIOpData_t *request = (const SwitchSPIOpData_t *)pBuf;
+ if (reply->spiReadData.opData.unAddress != request->unAddress ||
+ reply->spiReadData.opData.ucLength < request->ucLength) {
// This was a reply for another SPI read command
continue;
}