libsa: errors with pointer conversion

loader ip implementation is using pointer to structure ip to receive
the packet and is using this pointer to cast on other data types
(namely structure arphdr). Problem does arise when those data structures
are declared with different alignment rules and when/if the compiler
does check those rules. To work around and silence warnings, use
void * generic pointer instead.

Error seen with gcc 14 (-Werror=address-of-packed-member).

Reviewed by:    imp
Differential Revision: https://reviews.freebsd.org/D51662
This commit is contained in:
Toomas Soome
2025-07-31 22:11:16 +03:00
parent 0a3792d5c5
commit 733da235aa
+4 -2
View File
@@ -181,6 +181,7 @@ readipv4(struct iodesc *d, void **pkt, void **payload, time_t tleft,
ssize_t n;
size_t hlen;
struct ether_header *eh;
void *buf;
struct ip *ip;
struct udphdr *uh;
uint16_t etype; /* host order */
@@ -195,7 +196,7 @@ readipv4(struct iodesc *d, void **pkt, void **payload, time_t tleft,
ip = NULL;
ptr = NULL;
n = readether(d, (void **)&ptr, (void **)&ip, tleft, &etype);
n = readether(d, (void **)&ptr, (void **)&buf, tleft, &etype);
if (n == -1 || n < sizeof(*ip) + sizeof(*uh)) {
free(ptr);
return (-1);
@@ -205,7 +206,7 @@ readipv4(struct iodesc *d, void **pkt, void **payload, time_t tleft,
/* Need to respond to ARP requests. */
if (etype == ETHERTYPE_ARP) {
struct arphdr *ah = (void *)ip;
struct arphdr *ah = buf;
if (ah->ar_op == htons(ARPOP_REQUEST)) {
/* Send ARP reply */
arp_reply(d, ah);
@@ -224,6 +225,7 @@ readipv4(struct iodesc *d, void **pkt, void **payload, time_t tleft,
return (-1);
}
ip = buf;
/* Check ip header */
if (ip->ip_v != IPVERSION || /* half char */
ip->ip_p != proto) {