Skip to content

Commit 92ce860

Browse files
committed
Fix possible memory alignment issues
#34 (comment)
1 parent dd94cda commit 92ce860

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/exploit.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <iostream>
22
#include <sstream>
3+
#include <cstring>
34

45
#include <IPv6Layer.h>
56
#include <IPv4Layer.h>
@@ -87,11 +88,11 @@ struct Cookie {
8788
#define htole16
8889
#endif
8990

90-
#define V64BE(list, index, data) (*(uint64_t *) &(list)[index]) = htobe64(data)
91-
#define V64(list, index, data) (*(uint64_t *) &(list)[index]) = htole64(data)
92-
#define V32(list, index, data) (*(uint32_t *) &(list)[index]) = htole32(data)
93-
#define V16(list, index, data) (*(uint16_t *) &(list)[index]) = htole16(data)
94-
#define V8(list, index, data) (*(uint8_t *) &(list)[index]) = data
91+
#define V64BE(list, index, data) {uint64_t temp = htobe64(data); std::memcpy(&(list)[index], &temp, sizeof(uint64_t));}
92+
#define V64(list, index, data) {uint64_t temp = htole64(data); std::memcpy(&(list)[index], &temp, sizeof(uint64_t));}
93+
#define V32(list, index, data) {uint32_t temp = htole32(data); std::memcpy(&(list)[index], &temp, sizeof(uint32_t));}
94+
#define V16(list, index, data) {uint16_t temp = htole16(data); std::memcpy(&(list)[index], &temp, sizeof(uint16_t));}
95+
#define V8(list, index, data) {uint8_t temp = data; std::memcpy(&(list)[index], &temp, sizeof(uint8_t));}
9596

9697
#define CHECK_RET(value) { int ret = (value); if(ret != RETURN_SUCCESS) return ret;}
9798
#define CHECK_RUNNING() if (!running) return RETURN_STOP
@@ -937,7 +938,8 @@ int Exploit::stage2() {
937938
if (option[0] != 1) return false; // type 1 is ICMPv6NDOptSrcLLAddr
938939
if (option[1] > 1) {
939940
auto *self = (Exploit *) cookie;
940-
self->pppoe_softc_list = htole64(*(uint64_t * )(option + 3));
941+
std::memcpy(&self->pppoe_softc_list, option + 3, sizeof(uint64_t));
942+
self->pppoe_softc_list = htole64(self->pppoe_softc_list);
941943
return true; // length > 1
942944
}
943945
return false;

0 commit comments

Comments
 (0)