mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-03 14:08:52 +08:00
board_get_uuid: fix alignment issues
board_get_px4_guid() called board_get_uuid() with a 2 bytes offset into an uint8_t array. This gives no guarantees on alignment, and board_get_uuid() casts it to an uint32_t array, leading to potentially unaligned accesses.
This commit is contained in:
@@ -51,10 +51,12 @@ static const uint16_t soc_arch_id = PX4_SOC_ARCH_ID;
|
||||
void board_get_uuid(uuid_byte_t uuid_bytes)
|
||||
{
|
||||
uint32_t *chip_uuid = (uint32_t *) KINETIS_SIM_UIDH;
|
||||
uint32_t *uuid_words = (uint32_t *) uuid_bytes;
|
||||
uint32_t *uuid_words = (uint32_t *) uuid_bytes;
|
||||
|
||||
for (unsigned int i = 0; i < PX4_CPU_UUID_WORD32_LENGTH; i++) {
|
||||
*uuid_words++ = SWAP_UINT32(chip_uuid[i]);
|
||||
uint32_t current_uuid_bytes = SWAP_UINT32(chip_uuid[i]);
|
||||
memcpy(uuid_words, ¤t_uuid_bytes, sizeof(uint32_t));
|
||||
++uuid_words;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,10 +53,12 @@ const uint32_t DUMMY_SIM_UIDH[4] = {0x12345678, 0x12345678, 0x12345678, 0x123456
|
||||
void board_get_uuid(uuid_byte_t uuid_bytes)
|
||||
{
|
||||
uint32_t *chip_uuid = (uint32_t *) DUMMY_SIM_UIDH;
|
||||
uint32_t *uuid_words = (uint32_t *) uuid_bytes;
|
||||
uint32_t *uuid_words = (uint32_t *) uuid_bytes;
|
||||
|
||||
for (unsigned int i = 0; i < PX4_CPU_UUID_WORD32_LENGTH; i++) {
|
||||
*uuid_words++ = SWAP_UINT32(chip_uuid[i]);
|
||||
uint32_t current_uuid_bytes = SWAP_UINT32(chip_uuid[i]);
|
||||
memcpy(uuid_words, ¤t_uuid_bytes, sizeof(uint32_t));
|
||||
++uuid_words;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -141,7 +141,9 @@ int board_get_px4_guid(px4_guid_t px4_guid)
|
||||
uint32_t *chip_uuid = (uint32_t *) STM32_SYSMEM_UID;
|
||||
|
||||
for (unsigned i = 0; i < PX4_CPU_UUID_WORD32_LENGTH; i++) {
|
||||
*rv++ = SWAP_UINT32(chip_uuid[(PX4_CPU_UUID_WORD32_LENGTH - 1) - i]);
|
||||
uint32_t uuid_bytes = SWAP_UINT32(chip_uuid[(PX4_CPU_UUID_WORD32_LENGTH - 1) - i]);
|
||||
memcpy(rv, &uuid_bytes, sizeof(uint32_t));
|
||||
++rv;
|
||||
}
|
||||
|
||||
return PX4_GUID_BYTE_LENGTH;
|
||||
|
||||
Reference in New Issue
Block a user