Skip to content

Commit

Permalink
Fix possible memory alignment issues
Browse files Browse the repository at this point in the history
  • Loading branch information
xfangfang committed Nov 10, 2024
1 parent dd94cda commit 92ce860
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/exploit.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <iostream>
#include <sstream>
#include <cstring>

#include <IPv6Layer.h>
#include <IPv4Layer.h>
Expand Down Expand Up @@ -87,11 +88,11 @@ struct Cookie {
#define htole16
#endif

#define V64BE(list, index, data) (*(uint64_t *) &(list)[index]) = htobe64(data)
#define V64(list, index, data) (*(uint64_t *) &(list)[index]) = htole64(data)
#define V32(list, index, data) (*(uint32_t *) &(list)[index]) = htole32(data)
#define V16(list, index, data) (*(uint16_t *) &(list)[index]) = htole16(data)
#define V8(list, index, data) (*(uint8_t *) &(list)[index]) = data
#define V64BE(list, index, data) {uint64_t temp = htobe64(data); std::memcpy(&(list)[index], &temp, sizeof(uint64_t));}
#define V64(list, index, data) {uint64_t temp = htole64(data); std::memcpy(&(list)[index], &temp, sizeof(uint64_t));}
#define V32(list, index, data) {uint32_t temp = htole32(data); std::memcpy(&(list)[index], &temp, sizeof(uint32_t));}
#define V16(list, index, data) {uint16_t temp = htole16(data); std::memcpy(&(list)[index], &temp, sizeof(uint16_t));}
#define V8(list, index, data) {uint8_t temp = data; std::memcpy(&(list)[index], &temp, sizeof(uint8_t));}

#define CHECK_RET(value) { int ret = (value); if(ret != RETURN_SUCCESS) return ret;}
#define CHECK_RUNNING() if (!running) return RETURN_STOP
Expand Down Expand Up @@ -937,7 +938,8 @@ int Exploit::stage2() {
if (option[0] != 1) return false; // type 1 is ICMPv6NDOptSrcLLAddr
if (option[1] > 1) {
auto *self = (Exploit *) cookie;
self->pppoe_softc_list = htole64(*(uint64_t * )(option + 3));
std::memcpy(&self->pppoe_softc_list, option + 3, sizeof(uint64_t));
self->pppoe_softc_list = htole64(self->pppoe_softc_list);
return true; // length > 1
}
return false;
Expand Down

0 comments on commit 92ce860

Please sign in to comment.