Fixed bug 4968 - NULL passed to memcpy in WriteProprietary in SDL_hidapi_switch.c
authorSam Lantinga <slouken@libsdl.org>
Fri, 07 Feb 2020 11:49:56 -0800
changeset 134939ebdd8dfc588
parent 13492 c0f435c3bf24
child 13494 29809f6f0271
Fixed bug 4968 - NULL passed to memcpy in WriteProprietary in SDL_hidapi_switch.c

meyraud705

In SDL_hidapi_switch.c

line 443: Function BTrySetupUSB call WriteProprietary with pBuf=NULL and ucLen=0
line 376: WriteProprietary check its input (!pBuf && ucLen > 0) || ucLen > sizeof(packet.rgucProprietaryData): ucLen is 0 so it passes
line 382: WriteProprietary call memcpy with pBuf=NULL
src/joystick/hidapi/SDL_hidapi_switch.c
     1.1 --- a/src/joystick/hidapi/SDL_hidapi_switch.c	Fri Feb 07 11:45:32 2020 -0800
     1.2 +++ b/src/joystick/hidapi/SDL_hidapi_switch.c	Fri Feb 07 11:49:56 2020 -0800
     1.3 @@ -391,7 +391,9 @@
     1.4  
     1.5          packet.ucPacketType = k_eSwitchOutputReportIDs_Proprietary;
     1.6          packet.ucProprietaryID = ucCommand;
     1.7 -        SDL_memcpy(packet.rgucProprietaryData, pBuf, ucLen);
     1.8 +        if (pBuf) {
     1.9 +            SDL_memcpy(packet.rgucProprietaryData, pBuf, ucLen);
    1.10 +        }
    1.11  
    1.12          if (!WritePacket(ctx, &packet, sizeof(packet))) {
    1.13              continue;