| 1 |
/* Reduced test case from PR53703. Used to ICE. */ |
| 2 |
|
| 3 |
/* { dg-do compile } */ |
| 4 |
/* { dg-options "-w" } */ |
| 5 |
|
| 6 |
typedef long unsigned int size_t; |
| 7 |
typedef unsigned short int sa_family_t; |
| 8 |
struct sockaddr {}; |
| 9 |
typedef unsigned char __u8; |
| 10 |
typedef unsigned short __u16; |
| 11 |
typedef unsigned int __u32; |
| 12 |
struct nlmsghdr { |
| 13 |
__u32 nlmsg_len; |
| 14 |
__u16 nlmsg_type; |
| 15 |
}; |
| 16 |
struct ifaddrmsg { |
| 17 |
__u8 ifa_family; |
| 18 |
}; |
| 19 |
enum { |
| 20 |
IFA_ADDRESS, |
| 21 |
IFA_LOCAL, |
| 22 |
}; |
| 23 |
enum { |
| 24 |
RTM_NEWLINK = 16, |
| 25 |
RTM_NEWADDR = 20, |
| 26 |
}; |
| 27 |
struct rtattr { |
| 28 |
unsigned short rta_len; |
| 29 |
unsigned short rta_type; |
| 30 |
}; |
| 31 |
struct ifaddrs { |
| 32 |
struct ifaddrs *ifa_next; |
| 33 |
unsigned short ifa_flags; |
| 34 |
}; |
| 35 |
typedef unsigned short int uint16_t; |
| 36 |
typedef unsigned int uint32_t; |
| 37 |
struct nlmsg_list { |
| 38 |
struct nlmsg_list *nlm_next; |
| 39 |
int size; |
| 40 |
}; |
| 41 |
struct rtmaddr_ifamap { |
| 42 |
void *address; |
| 43 |
void *local; |
| 44 |
int address_len; |
| 45 |
int local_len; |
| 46 |
}; |
| 47 |
int ifa_sa_len (int, int); |
| 48 |
int usagi_getifaddrs (struct ifaddrs **ifap) |
| 49 |
{ |
| 50 |
struct nlmsg_list *nlmsg_list, *nlmsg_end, *nlm; |
| 51 |
size_t dlen, xlen, nlen; |
| 52 |
int build; |
| 53 |
for (build = 0; build <= 1; build++) |
| 54 |
{ |
| 55 |
struct ifaddrs *ifl = ((void *)0), *ifa = ((void *)0); |
| 56 |
struct nlmsghdr *nlh, *nlh0; |
| 57 |
uint16_t *ifflist = ((void *)0); |
| 58 |
struct rtmaddr_ifamap ifamap; |
| 59 |
for (nlm = nlmsg_list; nlm; nlm = nlm->nlm_next) |
| 60 |
{ |
| 61 |
int nlmlen = nlm->size; |
| 62 |
for (nlh = nlh0; |
| 63 |
((nlmlen) >= (int)sizeof(struct nlmsghdr) |
| 64 |
&& (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) |
| 65 |
&& (nlh)->nlmsg_len <= (nlmlen)); |
| 66 |
nlh = ((nlmlen) -= ( (((nlh)->nlmsg_len)+4U -1) & ~(4U -1) ), |
| 67 |
(struct nlmsghdr*)(((char*)(nlh)) |
| 68 |
+ ( (((nlh)->nlmsg_len)+4U -1) |
| 69 |
& ~(4U -1) )))) |
| 70 |
{ |
| 71 |
struct ifinfomsg *ifim = ((void *)0); |
| 72 |
struct ifaddrmsg *ifam = ((void *)0); |
| 73 |
struct rtattr *rta; |
| 74 |
sa_family_t nlm_family = 0; |
| 75 |
uint32_t nlm_scope = 0, nlm_index = 0; |
| 76 |
__builtin_memset (&ifamap, 0, sizeof (ifamap)); |
| 77 |
switch (nlh->nlmsg_type) |
| 78 |
{ |
| 79 |
case RTM_NEWLINK: |
| 80 |
ifim = (struct ifinfomsg *) |
| 81 |
((void*)(((char*)nlh) |
| 82 |
+ ((0)+( ((((int) |
| 83 |
( ((sizeof(struct nlmsghdr))+4U -1) |
| 84 |
& ~(4U -1) )))+4U -1) |
| 85 |
& ~(4U -1) )))); |
| 86 |
case RTM_NEWADDR: |
| 87 |
ifam = (struct ifaddrmsg *) |
| 88 |
((void*)(((char*)nlh) |
| 89 |
+ ((0)+( ((((int) |
| 90 |
( ((sizeof(struct nlmsghdr))+4U -1) |
| 91 |
& ~(4U -1) )))+4U -1) |
| 92 |
& ~(4U -1) )))); |
| 93 |
nlm_family = ifam->ifa_family; |
| 94 |
if (build) |
| 95 |
ifa->ifa_flags = ifflist[nlm_index]; |
| 96 |
break; |
| 97 |
default: |
| 98 |
continue; |
| 99 |
} |
| 100 |
if (!build) |
| 101 |
{ |
| 102 |
void *rtadata = ((void*)(((char*)(rta)) |
| 103 |
+ (( ((sizeof(struct rtattr))+4 -1) |
| 104 |
& ~(4 -1) ) + (0)))); |
| 105 |
size_t rtapayload = ((int)((rta)->rta_len) |
| 106 |
- (( ((sizeof(struct rtattr))+4 -1) |
| 107 |
& ~(4 -1) ) + (0))); |
| 108 |
switch (nlh->nlmsg_type) |
| 109 |
{ |
| 110 |
case RTM_NEWLINK: |
| 111 |
break; |
| 112 |
case RTM_NEWADDR: |
| 113 |
if (nlm_family == 17) |
| 114 |
break; |
| 115 |
switch (rta->rta_type) |
| 116 |
{ |
| 117 |
case IFA_ADDRESS: |
| 118 |
ifamap.address = rtadata; |
| 119 |
ifamap.address_len = rtapayload; |
| 120 |
case IFA_LOCAL: |
| 121 |
ifamap.local = rtadata; |
| 122 |
} |
| 123 |
} |
| 124 |
} |
| 125 |
if (nlh->nlmsg_type == RTM_NEWADDR && nlm_family != 17) |
| 126 |
{ |
| 127 |
if (!ifamap.local) |
| 128 |
{ |
| 129 |
ifamap.local = ifamap.address; |
| 130 |
ifamap.local_len = ifamap.address_len; |
| 131 |
} |
| 132 |
if (!ifamap.address) |
| 133 |
{ |
| 134 |
ifamap.address = ifamap.local; |
| 135 |
} |
| 136 |
if (ifamap.address_len != ifamap.local_len |
| 137 |
|| (ifamap.address != ((void *)0) |
| 138 |
&& __builtin_memcmp (ifamap.address, ifamap.local, |
| 139 |
ifamap.address_len))) |
| 140 |
{ |
| 141 |
if (!build) |
| 142 |
dlen += (((ifa_sa_len (nlm_family, |
| 143 |
ifamap.address_len))+4U -1) |
| 144 |
& ~(4U -1) ); |
| 145 |
} |
| 146 |
} |
| 147 |
} |
| 148 |
} |
| 149 |
} |
| 150 |
} |