Skip to content

Commit 88b2731

Browse files
author
marek
committed
[batman] Word-Align char buffer which are later casted to larger data types
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 <[email protected]> git-svn-id: http://downloads.open-mesh.org/svn/batman/trunk/batman@1281 45894c77-fb22-0410-b583-ff6e7d5dbf6c
1 parent ad4d65c commit 88b2731

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

batman.h

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152

153153

154154
#define BATMANUNUSED(x) (x)__attribute__((unused))
155+
#define ALIGN_WORD __attribute__ ((aligned(sizeof(TYPE_OF_WORD))))
155156

156157

157158

linux/route.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ void add_del_route(uint32_t dest, uint8_t netmask, uint32_t router, uint32_t src
185185
struct rtmsg rtm;
186186
char buff[4 * (sizeof(struct rtattr) + 4)];
187187
} *req;
188-
char req_buf[NLMSG_LENGTH(sizeof(struct req_s))];
188+
char req_buf[NLMSG_LENGTH(sizeof(struct req_s))] ALIGN_WORD;
189189

190190
iov.iov_base = buf;
191191
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
369369
struct rtmsg rtm;
370370
char buff[2 * (sizeof(struct rtattr) + 4)];
371371
} *req;
372-
char req_buf[NLMSG_LENGTH(sizeof(struct req_s))];
372+
char req_buf[NLMSG_LENGTH(sizeof(struct req_s))] ALIGN_WORD;
373373

374374
iov.iov_base = buf;
375375
iov.iov_len = sizeof(buf);
@@ -634,7 +634,7 @@ int flush_routes_rules(int8_t is_rule)
634634
struct req_s {
635635
struct rtmsg rtm;
636636
} *req;
637-
char req_buf[NLMSG_LENGTH(sizeof(struct req_s))];
637+
char req_buf[NLMSG_LENGTH(sizeof(struct req_s))] ALIGN_WORD;
638638

639639
struct rtattr *rtap;
640640

posix/tunnel.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ void *gw_listen(void *BATMANUNUSED(arg)) {
567567
unsigned char buff[1501];
568568
int32_t res, max_sock, buff_len, tun_fd, tun_ifi;
569569
uint32_t addr_len, client_timeout, current_time;
570-
uint8_t my_tun_ip[4], next_free_ip[4];
570+
uint8_t my_tun_ip[4] ALIGN_WORD, next_free_ip[4] ALIGN_WORD;
571571
struct hashtable_t *wip_hash, *vip_hash;
572572
struct list_head_first free_ip_list;
573573
fd_set wait_sockets, tmp_wait_sockets;

0 commit comments

Comments
 (0)