Klaus Demo nginx / d469482
Fixed strict aliasing bugs when dealing with IPv4-mapped IPv6 addresses (closes #201). Ruslan Ermilov 8 years ago
3 changed file(s) with 29 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
232232 #if (NGX_HAVE_INET6)
233233
234234 if (addr.sockaddr->sa_family == AF_INET6) {
235 u_char *p;
236 in_addr_t inaddr;
235237 struct in6_addr *inaddr6;
236238
237239 inaddr6 = &((struct sockaddr_in6 *) addr.sockaddr)->sin6_addr;
238240
239241 if (IN6_IS_ADDR_V4MAPPED(inaddr6)) {
240 return ntohl(*(in_addr_t *) &inaddr6->s6_addr[12]);
242 p = inaddr6->s6_addr;
243
244 inaddr = p[12] << 24;
245 inaddr += p[13] << 16;
246 inaddr += p[14] << 8;
247 inaddr += p[15];
248
249 return inaddr;
241250 }
242251 }
243252
225225 #if (NGX_HAVE_INET6)
226226
227227 if (addr.sockaddr->sa_family == AF_INET6) {
228 u_char *p;
229 in_addr_t inaddr;
228230 struct in6_addr *inaddr6;
229231
230232 inaddr6 = &((struct sockaddr_in6 *) addr.sockaddr)->sin6_addr;
231233
232234 if (IN6_IS_ADDR_V4MAPPED(inaddr6)) {
233 return ntohl(*(in_addr_t *) &inaddr6->s6_addr[12]);
235 p = inaddr6->s6_addr;
236
237 inaddr = p[12] << 24;
238 inaddr += p[13] << 16;
239 inaddr += p[14] << 8;
240 inaddr += p[15];
241
242 return inaddr;
234243 }
235244 }
236245
27752775
27762776 if (IN6_IS_ADDR_V4MAPPED(inaddr6)) {
27772777 family = AF_INET;
2778 inaddr = *(in_addr_t *) &inaddr6->s6_addr[12];
2778
2779 p = inaddr6->s6_addr;
2780
2781 inaddr = p[12] << 24;
2782 inaddr += p[13] << 16;
2783 inaddr += p[14] << 8;
2784 inaddr += p[15];
2785
2786 inaddr = htonl(inaddr);
27792787 }
27802788 }
27812789 #endif