From 372b9cae7a9832f25e2b528ec9b1968472230c32 Mon Sep 17 00:00:00 2001 From: Mihai Parparita Date: Thu, 15 Aug 2024 22:32:46 -0700 Subject: [PATCH] atapibasedevice: fix unaligned memory access Both cmd_pkt and data_buf class members are cast to a uint16_t pointer, so we need to make sure they are properly aligned, otherwise it is undefined behavior. --- devices/common/ata/atabasedevice.h | 1 + devices/common/ata/atapibasedevice.h | 1 + 2 files changed, 2 insertions(+) diff --git a/devices/common/ata/atabasedevice.h b/devices/common/ata/atabasedevice.h index 3077fe6..54959a7 100644 --- a/devices/common/ata/atabasedevice.h +++ b/devices/common/ata/atabasedevice.h @@ -96,6 +96,7 @@ protected: uint16_t *data_ptr = nullptr; uint16_t *cur_data_ptr = nullptr; + alignas(uint16_t) uint8_t data_buf[512] = {}; int xfer_cnt = 0; int chunk_cnt = 0; diff --git a/devices/common/ata/atapibasedevice.h b/devices/common/ata/atapibasedevice.h index 39d0f74..598112a 100644 --- a/devices/common/ata/atapibasedevice.h +++ b/devices/common/ata/atapibasedevice.h @@ -55,6 +55,7 @@ protected: uint16_t r_byte_count; bool status_expected = false; + alignas(uint16_t) uint8_t cmd_pkt[12] = {}; };