Преглед изворни кода

[Bug] XAP: Fix unaligned memory access in config blob handler and USB task loop condition (#18612)

* Fix unaligned memory access in config blob handler

data* points in the middle of an u8 array, casting this to an u16* and
dereferencing it leads to an unaligned memory access - which hardfaults
on Cortex M0 mcus e.g. RP2040s.

* Actually read until there is no more data to be read
Stefan Kerkmann пре 3 година
родитељ
комит
907640e40e
2 измењених фајлова са 3 додато и 2 уклоњено
  1. 2 1
      quantum/xap/xap_handlers.c
  2. 1 1
      tmk_core/protocol/chibios/usb_main.c

+ 2 - 1
quantum/xap/xap_handlers.c

@@ -64,7 +64,8 @@ bool xap_respond_get_config_blob_chunk(xap_token_t token, const void *data, size
         return false;
     }
 
-    uint16_t offset = *((uint16_t *)data);
+    uint16_t offset;
+    memcpy(&offset, data, sizeof(uint16_t));
 
     xap_route_qmk_config_blob_chunk_t ret = {0};
 

+ 1 - 1
tmk_core/protocol/chibios/usb_main.c

@@ -1165,7 +1165,7 @@ void xap_task(void) {
     uint8_t buffer[XAP_EPSIZE];
     size_t  size = 0;
     do {
-        size_t size = chnReadTimeout(&drivers.xap_driver.driver, buffer, sizeof(buffer), TIME_IMMEDIATE);
+        size = chnReadTimeout(&drivers.xap_driver.driver, buffer, sizeof(buffer), TIME_IMMEDIATE);
         if (size > 0) {
             xap_receive_base(buffer);
         }