From bec60340076215ee0908e60231ff361b2abc0c87 Mon Sep 17 00:00:00 2001 From: Leonardo Alminana Date: Wed, 7 Aug 2024 16:02:38 +0200 Subject: [PATCH] log_event_decoder: updated code to use aligned memory reads This will not change the underlying code for 99.9% of the users, however, when specifically enabled it through the FLB_ENFORCE_ALIGNMENT feature flag, FLB_ALIGNED_DWORD_READ will issue four BYTE sized reads instead of a single DWORD sized read to ensure that memory access is aligned. Signed-off-by: Leonardo Alminana --- src/flb_log_event_decoder.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/flb_log_event_decoder.c b/src/flb_log_event_decoder.c index 53cf1c63412..3e8ca6e56d4 100644 --- a/src/flb_log_event_decoder.c +++ b/src/flb_log_event_decoder.c @@ -19,6 +19,7 @@ #include #include +#include static int create_empty_map(struct flb_log_event_decoder *context) { msgpack_packer packer; @@ -179,8 +180,15 @@ int flb_log_event_decoder_decode_timestamp(msgpack_object *input, return FLB_EVENT_DECODER_ERROR_WRONG_TIMESTAMP_TYPE; } - output->tm.tv_sec = (int32_t) FLB_BSWAP_32(*((uint32_t *) &input->via.ext.ptr[0])); - output->tm.tv_nsec = (int32_t) FLB_BSWAP_32(*((uint32_t *) &input->via.ext.ptr[4])); + output->tm.tv_sec = + (int32_t) FLB_BSWAP_32( + FLB_ALIGNED_DWORD_READ( + (unsigned char *) &input->via.ext.ptr[0])); + + output->tm.tv_nsec = + (int32_t) FLB_BSWAP_32( + FLB_ALIGNED_DWORD_READ( + (unsigned char *) &input->via.ext.ptr[4])); } else { return FLB_EVENT_DECODER_ERROR_WRONG_TIMESTAMP_TYPE;