From b3351d3ab086f69490c9f8d6bc8150a663fc626d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Lind=C3=A9n?= Date: Tue, 15 Nov 2016 19:45:50 +0100 Subject: [PATCH 1/3] Set SAVED_FRIEND to always have 8-byte alignment. --- toxcore/Messenger.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 77a19f30d9..6c72f77f1c 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -2633,6 +2633,8 @@ void do_messenger(Messenger *m, void *userdata) #define SAVED_FRIEND_REQUEST_SIZE 1024 #define NUM_SAVED_PATH_NODES 8 + +#pragma pack(push, 8) struct SAVED_FRIEND { uint8_t status; uint8_t real_pk[crypto_box_PUBLICKEYBYTES]; @@ -2646,6 +2648,7 @@ struct SAVED_FRIEND { uint32_t friendrequest_nospam; uint64_t last_seen_time; }; +#pragma pack(pop) static uint32_t saved_friendslist_size(const Messenger *m) { From 092cb4e6ae6786ad1caae27bc4dae068142f4cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Lind=C3=A9n?= Date: Wed, 16 Nov 2016 00:07:06 +0100 Subject: [PATCH 2/3] Manually aligned SAVED_FRIEND struct. --- toxcore/Messenger.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 6c72f77f1c..a8694fbfdc 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -2634,21 +2634,23 @@ void do_messenger(Messenger *m, void *userdata) #define SAVED_FRIEND_REQUEST_SIZE 1024 #define NUM_SAVED_PATH_NODES 8 -#pragma pack(push, 8) struct SAVED_FRIEND { uint8_t status; uint8_t real_pk[crypto_box_PUBLICKEYBYTES]; - uint8_t info[SAVED_FRIEND_REQUEST_SIZE]; // the data that is sent during the friend requests we do. + uint8_t info[SAVED_FRIEND_REQUEST_SIZE]; + // ^ The data sent during the friend requests we do. + uint8_t : 1; // padding uint16_t info_size; // Length of the info. uint8_t name[MAX_NAME_LENGTH]; + uint8_t : 1; // padding uint16_t name_length; uint8_t statusmessage[MAX_STATUSMESSAGE_LENGTH]; uint16_t statusmessage_length; uint8_t userstatus; + uint8_t : 5; // padding uint32_t friendrequest_nospam; uint64_t last_seen_time; -}; -#pragma pack(pop) +} __attribute__ ((aligned (8))); static uint32_t saved_friendslist_size(const Messenger *m) { From dec2fee012a51cf0df45d630a3157096e1f66317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Lind=C3=A9n?= Date: Wed, 16 Nov 2016 00:48:29 +0100 Subject: [PATCH 3/3] Bits vs bytes. --- toxcore/Messenger.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index a8694fbfdc..086f0fe22c 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -2639,18 +2639,21 @@ struct SAVED_FRIEND { uint8_t real_pk[crypto_box_PUBLICKEYBYTES]; uint8_t info[SAVED_FRIEND_REQUEST_SIZE]; // ^ The data sent during the friend requests we do. - uint8_t : 1; // padding + uint8_t : 8; // padding uint16_t info_size; // Length of the info. uint8_t name[MAX_NAME_LENGTH]; - uint8_t : 1; // padding uint16_t name_length; uint8_t statusmessage[MAX_STATUSMESSAGE_LENGTH]; + uint8_t : 8; // padding uint16_t statusmessage_length; uint8_t userstatus; - uint8_t : 5; // padding + uint8_t : 8; // padding + uint16_t : 16; // padding uint32_t friendrequest_nospam; uint64_t last_seen_time; } __attribute__ ((aligned (8))); +// __attribute__ ((aligned (8))) *shouldn't* do anything, as everything's +// manually aligned to 8-byte boundaries but left it in to be on the safe side. static uint32_t saved_friendslist_size(const Messenger *m) {