Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ambrop72/badvpn.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/udpgw
diff options
context:
space:
mode:
authorambrop7 <ambrop7@1a93d707-3861-5ebc-ad3b-9740d49b5140>2012-12-30 07:20:36 +0400
committerambrop7 <ambrop7@1a93d707-3861-5ebc-ad3b-9740d49b5140>2012-12-30 07:20:36 +0400
commit2185655723f2dc2bdd85074b08cfb1ef529ff17c (patch)
tree7c15207cf0e9f4fa2aaaba56007481ce4c4895a1 /udpgw
parent27bafc71f7d4fa9ce64434708d043545aaba5ea5 (diff)
fix many potential aliasing issues
Diffstat (limited to 'udpgw')
-rw-r--r--udpgw/udpgw.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/udpgw/udpgw.c b/udpgw/udpgw.c
index aac3848..c5ef6c4 100644
--- a/udpgw/udpgw.c
+++ b/udpgw/udpgw.c
@@ -772,11 +772,12 @@ void client_recv_if_handler_send (struct client *client, uint8_t *data, int data
client_log(client, BLOG_ERROR, "missing header");
return;
}
- struct udpgw_header *header = (struct udpgw_header *)data;
- data += sizeof(*header);
- data_len -= sizeof(*header);
- uint8_t flags = ltoh8(header->flags);
- uint16_t conid = ltoh16(header->conid);
+ struct udpgw_header header;
+ memcpy(&header, data, sizeof(header));
+ data += sizeof(header);
+ data_len -= sizeof(header);
+ uint8_t flags = ltoh8(header.flags);
+ uint16_t conid = ltoh16(header.conid);
// reset disconnect timer
BReactor_SetTimer(&ss, &client->disconnect_timer);
@@ -798,7 +799,7 @@ void client_recv_if_handler_send (struct client *client, uint8_t *data, int data
ASSERT(!con || !con->closing)
// if connection exists, close it if needed
- if (con && ((flags & UDPGW_CLIENT_FLAG_REBIND) || con->addr.ipv4.ip != header->addr_ip || con->addr.ipv4.port != header->addr_port)) {
+ if (con && ((flags & UDPGW_CLIENT_FLAG_REBIND) || con->addr.ipv4.ip != header.addr_ip || con->addr.ipv4.port != header.addr_port)) {
connection_log(con, BLOG_DEBUG, "close old");
connection_close(con);
@@ -816,7 +817,7 @@ void client_recv_if_handler_send (struct client *client, uint8_t *data, int data
// read address
BAddr addr;
- BAddr_InitIPv4(&addr, header->addr_ip, header->addr_port);
+ BAddr_InitIPv4(&addr, header.addr_ip, header.addr_port);
// create new connection
connection_init(client, conid, addr, data, data_len);
@@ -1147,17 +1148,18 @@ int connection_send_to_client (struct connection *con, uint8_t flags, const uint
}
// write header
- struct udpgw_header *header = (struct udpgw_header *)out;
- header->flags = htol8(flags);
- header->conid = htol16(con->conid);
- header->addr_ip = con->addr.ipv4.ip;
- header->addr_port = con->addr.ipv4.port;
+ struct udpgw_header header;
+ header.flags = htol8(flags);
+ header.conid = htol16(con->conid);
+ header.addr_ip = con->addr.ipv4.ip;
+ header.addr_port = con->addr.ipv4.port;
+ memcpy(out, &header, sizeof(header));
// write message
- memcpy(out + sizeof(*header), data, data_len);
+ memcpy(out + sizeof(header), data, data_len);
// submit written message
- BufferWriter_EndPacket(con->send_if, sizeof(*header) + data_len);
+ BufferWriter_EndPacket(con->send_if, sizeof(header) + data_len);
return 1;
}