sgsnemu: Fix unaligned pointer access during ip/icmp checksum
Catched by gcc 9.1.0: osmo-ggsn/sgsnemu/sgsnemu.c:1294:2: error: converting a packed struct ip_ping pointer (alignment 1) to a uint16_t {aka short unsigned int} pointer (alignment 2) may result in an unaligned pointer value [-Werror=address-of-packed-member] 1294 | p = (uint16_t *) & pack; Change-Id: I783f104c31234a07f2a13f6dbc577a71b25b36a7
This commit is contained in:
parent
f1e01517bc
commit
e47932976c
|
@ -1234,7 +1234,7 @@ static int create_ping(void *gsn, struct pdp_t *pdp,
|
||||||
{
|
{
|
||||||
|
|
||||||
struct ip_ping pack;
|
struct ip_ping pack;
|
||||||
uint16_t *p = (uint16_t *) & pack;
|
uint16_t v16;
|
||||||
uint8_t *p8 = (uint8_t *) & pack;
|
uint8_t *p8 = (uint8_t *) & pack;
|
||||||
struct in_addr src;
|
struct in_addr src;
|
||||||
unsigned int n;
|
unsigned int n;
|
||||||
|
@ -1270,7 +1270,7 @@ static int create_ping(void *gsn, struct pdp_t *pdp,
|
||||||
pack.seq = htons(seq);
|
pack.seq = htons(seq);
|
||||||
|
|
||||||
/* Generate ICMP payload */
|
/* Generate ICMP payload */
|
||||||
p8 = (uint8_t *) & pack + CREATEPING_IP + CREATEPING_ICMP;
|
p8 = (uint8_t *) &pack + CREATEPING_IP + CREATEPING_ICMP;
|
||||||
for (n = 0; n < (datasize); n++)
|
for (n = 0; n < (datasize); n++)
|
||||||
p8[n] = n;
|
p8[n] = n;
|
||||||
|
|
||||||
|
@ -1278,11 +1278,13 @@ static int create_ping(void *gsn, struct pdp_t *pdp,
|
||||||
gettimeofday(tp, &tz);
|
gettimeofday(tp, &tz);
|
||||||
|
|
||||||
/* Calculate IP header checksum */
|
/* Calculate IP header checksum */
|
||||||
p = (uint16_t *) & pack;
|
p8 = (uint8_t *) &pack;
|
||||||
count = CREATEPING_IP;
|
count = CREATEPING_IP;
|
||||||
sum = 0;
|
sum = 0;
|
||||||
while (count > 1) {
|
while (count > 1) {
|
||||||
sum += *p++;
|
memcpy(&v16, p8, 2);
|
||||||
|
sum += v16;
|
||||||
|
p8 += 2;
|
||||||
count -= 2;
|
count -= 2;
|
||||||
}
|
}
|
||||||
while (sum >> 16)
|
while (sum >> 16)
|
||||||
|
@ -1292,14 +1294,16 @@ static int create_ping(void *gsn, struct pdp_t *pdp,
|
||||||
/* Calculate ICMP checksum */
|
/* Calculate ICMP checksum */
|
||||||
count = CREATEPING_ICMP + datasize; /* Length of ICMP message */
|
count = CREATEPING_ICMP + datasize; /* Length of ICMP message */
|
||||||
sum = 0;
|
sum = 0;
|
||||||
p = (uint16_t *) & pack;
|
p8 = (uint8_t *) &pack;
|
||||||
p += CREATEPING_IP / 2;
|
p8 += CREATEPING_IP;
|
||||||
while (count > 1) {
|
while (count > 1) {
|
||||||
sum += *p++;
|
memcpy(&v16, p8, 2);
|
||||||
|
sum += v16;
|
||||||
|
p8 += 2;
|
||||||
count -= 2;
|
count -= 2;
|
||||||
}
|
}
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
sum += *(unsigned char *)p;
|
sum += *(unsigned char *)p8;
|
||||||
while (sum >> 16)
|
while (sum >> 16)
|
||||||
sum = (sum & 0xffff) + (sum >> 16);
|
sum = (sum & 0xffff) + (sum >> 16);
|
||||||
pack.checksum = ~sum;
|
pack.checksum = ~sum;
|
||||||
|
|
Loading…
Reference in New Issue