Skip to content

Commit c7920fa

Browse files
committed
MDEV-16264: Eliminate unsafe os_aio_userdata_t type cast
1 parent 8be3794 commit c7920fa

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

storage/innobase/include/os0file.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,12 @@ struct os_aio_userdata_t
13501350
fil_node_t* node;
13511351
IORequest type;
13521352
void* message;
1353+
1354+
os_aio_userdata_t(fil_node_t*node, IORequest type, void*message) :
1355+
node(node), type(type), message(message) {}
1356+
1357+
/** Construct from tpool::aiocb::m_userdata[] */
1358+
os_aio_userdata_t(const char *buf) { memcpy((void*)this, buf, sizeof*this); }
13531359
};
13541360
/**
13551361
NOTE! Use the corresponding macro os_aio(), not directly this function!

storage/innobase/os/os0file.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3883,7 +3883,7 @@ extern void fil_aio_callback(os_aio_userdata_t *data);
38833883
static void io_callback(tpool::aiocb* cb)
38843884
{
38853885
ut_a(cb->m_err == DB_SUCCESS);
3886-
os_aio_userdata_t data = *(os_aio_userdata_t*)cb->m_userdata;
3886+
os_aio_userdata_t data(cb->m_userdata);
38873887
/* Return cb back to cache*/
38883888
if (cb->m_opcode == tpool::aio_opcode::AIO_PREAD) {
38893889
if (read_slots->contains(cb)) {

tpool/tpool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ struct aiocb
137137
int m_err;
138138
void *m_internal;
139139
task m_internal_task;
140-
char m_userdata[MAX_AIO_USERDATA_LEN];
140+
alignas(8) char m_userdata[MAX_AIO_USERDATA_LEN];
141141

142142
aiocb() : m_internal_task(nullptr, nullptr)
143143
{}

0 commit comments

Comments
 (0)