This is an automated email from Gerrit.

"Antonio Borneo <borneo.anto...@gmail.com>" just uploaded a new patch set to 
Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8473

-- gerrit

commit ec73b44e485c674906cae3ad779c3ec6d5a9832a
Author: Antonio Borneo <borneo.anto...@gmail.com>
Date:   Sun Sep 1 14:45:36 2024 +0200

    rtos: chibios: fix version display
    
    The field 'struct chibios_chdebug::ch_version' is 16 bits wide, so
    using le_to_h_u32() and be_to_h_u32() overflows in the following
    fields of the struct.
    
    Restrict the endianness conversion to 16 bits and use the target
    endianness dependent target_buffer_get_u16().
    Convert the 'struct chibios_chdebug::ch_version' to an array of
    uint8_t.
    
    Change-Id: Iaa80e9cb1a65c27512919398b8ffbf14e5c240cd
    Signed-off-by: Antonio Borneo <borneo.anto...@gmail.com>

diff --git a/src/rtos/chibios.c b/src/rtos/chibios.c
index c1e4e84192..f4ee33a490 100644
--- a/src/rtos/chibios.c
+++ b/src/rtos/chibios.c
@@ -31,7 +31,7 @@ struct chibios_chdebug {
        char      ch_identifier[4];       /**< @brief Always set to "main".     
  */
        uint8_t   ch_zero;                /**< @brief Must be zero.             
  */
        uint8_t   ch_size;                /**< @brief Size of this structure.   
  */
-       uint16_t  ch_version;             /**< @brief Encoded ChibiOS/RT 
version. */
+       uint8_t   ch_version[2];          /**< @brief Encoded ChibiOS/RT 
version. */
        uint8_t   ch_ptrsize;             /**< @brief Size of a pointer.        
  */
        uint8_t   ch_timesize;            /**< @brief Size of a @p systime_t.   
  */
        uint8_t   ch_threadsize;          /**< @brief Size of a @p Thread 
struct. */
@@ -171,13 +171,7 @@ static int chibios_update_memory_signature(struct rtos 
*rtos)
                                        " expected. Assuming compatibility...");
        }
 
-       /* Convert endianness of version field */
-       const uint8_t *versiontarget = (const uint8_t *)
-                                                                               
&signature->ch_version;
-       signature->ch_version = rtos->target->endianness == 
TARGET_LITTLE_ENDIAN ?
-                       le_to_h_u32(versiontarget) : be_to_h_u32(versiontarget);
-
-       const uint16_t ch_version = signature->ch_version;
+       const uint16_t ch_version = target_buffer_get_u16(rtos->target, 
signature->ch_version);
        LOG_INFO("Successfully loaded memory map of ChibiOS/RT target "
                        "running version %i.%i.%i", 
GET_CH_KERNEL_MAJOR(ch_version),
                        GET_CH_KERNEL_MINOR(ch_version), 
GET_CH_KERNEL_PATCH(ch_version));

-- 

Reply via email to