From d98ca97624d8b5a8099d03ee336b596543bc820f Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Mon, 29 Jul 2024 13:17:37 +0200 Subject: [PATCH] Fix unaligned load of 4 bytes for typeid Use memcpy() to move the typeid to an aligned address. --- src/emu/nanos6/event.c | 5 +++-- src/emu/nosv/event.c | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/emu/nanos6/event.c b/src/emu/nanos6/event.c index f7bf3d3..ae1aaf2 100644 --- a/src/emu/nanos6/event.c +++ b/src/emu/nanos6/event.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC) +/* Copyright (c) 2021-2024 Barcelona Supercomputing Center (BSC) * SPDX-License-Identifier: GPL-3.0-or-later */ #include "nanos6_priv.h" @@ -521,7 +521,8 @@ pre_type(struct emu *emu) } const uint8_t *data = &emu->ev->payload->jumbo.data[0]; - uint32_t typeid = *(uint32_t *) data; + uint32_t typeid; + memcpy(&typeid, data, 4); /* May be unaligned */ data += 4; const char *label = (const char *) data; diff --git a/src/emu/nosv/event.c b/src/emu/nosv/event.c index 9e47fae..52b7d8a 100644 --- a/src/emu/nosv/event.c +++ b/src/emu/nosv/event.c @@ -546,7 +546,8 @@ pre_type(struct emu *emu) } const uint8_t *data = &emu->ev->payload->jumbo.data[0]; - uint32_t typeid = *(uint32_t *) data; + uint32_t typeid; + memcpy(&typeid, data, 4); /* May be unaligned */ data += 4; const char *label = (const char *) data;