[3/3] Word-Align char buffer which are later casted to larger data types
Commit Message
Buffers of char must not be special aligned on all architecture, but
if the compiler will not know about missing alignment of the larger
data type it generate unsafe instructions as it assumes that they
are word aligned.
Signed-off-by: Sven Eckelmann <sven.eckelmann@gmx.de>
---
batman/batman.h | 1 +
batman/linux/route.c | 6 +++---
batman/posix/tunnel.c | 2 +-
3 files changed, 5 insertions(+), 4 deletions(-)
@@ -152,6 +152,7 @@
#define BATMANUNUSED(x) (x)__attribute__((unused))
+#define ALIGN_WORD __attribute__ ((aligned(sizeof(TYPE_OF_WORD))))
@@ -185,7 +185,7 @@ void add_del_route(uint32_t dest, uint8_t netmask, uint32_t router, uint32_t src
struct rtmsg rtm;
char buff[4 * (sizeof(struct rtattr) + 4)];
} *req;
- char req_buf[NLMSG_LENGTH(sizeof(struct req_s))];
+ char req_buf[NLMSG_LENGTH(sizeof(struct req_s))] ALIGN_WORD;
iov.iov_base = buf;
iov.iov_len = sizeof(buf);
@@ -369,7 +369,7 @@ void add_del_rule(uint32_t network, uint8_t netmask, int8_t rt_table, uint32_t p
struct rtmsg rtm;
char buff[2 * (sizeof(struct rtattr) + 4)];
} *req;
- char req_buf[NLMSG_LENGTH(sizeof(struct req_s))];
+ char req_buf[NLMSG_LENGTH(sizeof(struct req_s))] ALIGN_WORD;
iov.iov_base = buf;
iov.iov_len = sizeof(buf);
@@ -634,7 +634,7 @@ int flush_routes_rules(int8_t is_rule)
struct req_s {
struct rtmsg rtm;
} *req;
- char req_buf[NLMSG_LENGTH(sizeof(struct req_s))];
+ char req_buf[NLMSG_LENGTH(sizeof(struct req_s))] ALIGN_WORD;
struct rtattr *rtap;
@@ -567,7 +567,7 @@ void *gw_listen(void *BATMANUNUSED(arg)) {
unsigned char buff[1501];
int32_t res, max_sock, buff_len, tun_fd, tun_ifi;
uint32_t addr_len, client_timeout, current_time;
- uint8_t my_tun_ip[4], next_free_ip[4];
+ uint8_t my_tun_ip[4] ALIGN_WORD, next_free_ip[4] ALIGN_WORD;
struct hashtable_t *wip_hash, *vip_hash;
struct list_head_first free_ip_list;
fd_set wait_sockets, tmp_wait_sockets;