MaJerle / stm32fxxx-hal-libraries

Libraries for STM32F4xx and STM32F7xx built on HAL drivers from ST
MIT License
752 stars 432 forks source link

Unitialized pointer dereference at tm_stm32_usb_host_hid.c L123&124 #15

Closed cstratton closed 7 years ago

cstratton commented 7 years ago

The k_minfinfo structure pointer is dereferenced before being assigned at line 123 and 124 of.

http://github.com/MaJerle/stm32fxxx_hal_libraries/blob/master/00-STM32_LIBRARIES/tm_stm32_usb_host_hid.c#L123

HID_MOUSE_Info_TypeDef* k_minfo;
uint8_t i;

/* Reset relative values */
MouseStruct->RelativeX =  (int8_t)k_minfo->x;
MouseStruct->RelativeY = (int8_t)k_minfo->y;

/* Get keyboard informations */
k_minfo = USBH_HID_GetMouseInfo(TM_USBH_GetUSBPointer(USB_Mode));

This randomly causes a hard fault, presumably due to illegal memory access

Perhaps you could just zero these in case (or if) the USBH_HID_GetMouseInfo() call returns NULL.