[nginx] svn commit: r4858 - in branches/stable-1.2: . src/http src/http/modules

mdounin at mdounin.ru mdounin at mdounin.ru
Mon Sep 24 19:06:48 UTC 2012


Author: mdounin
Date: 2012-09-24 19:06:48 +0000 (Mon, 24 Sep 2012)
New Revision: 4858
URL: http://trac.nginx.org/nginx/changeset/4858/nginx

Log:
Merge of r4829: fixed strict aliasing with ipv6 (ticket #201).

Fixed strict aliasing bugs when dealing with IPv4-mapped IPv6
addresses.


Modified:
   branches/stable-1.2/
   branches/stable-1.2/src/http/modules/ngx_http_geo_module.c
   branches/stable-1.2/src/http/modules/ngx_http_geoip_module.c
   branches/stable-1.2/src/http/ngx_http_core_module.c

Index: branches/stable-1.2
===================================================================
--- branches/stable-1.2	2012-09-24 19:05:02 UTC (rev 4857)
+++ branches/stable-1.2	2012-09-24 19:06:48 UTC (rev 4858)

Property changes on: branches/stable-1.2
___________________________________________________________________
Modified: svn:mergeinfo
## -1 +1 ##
-/trunk:4611-4632,4636-4657,4671-4672,4674-4676,4682,4684-4699,4704-4706,4713,4736-4741,4754,4756-4771,4775,4777-4780,4782-4785,4795,4811-4820,4822-4824,4828,4830-4832,4834,4840,4842-4844
+/trunk:4611-4632,4636-4657,4671-4672,4674-4676,4682,4684-4699,4704-4706,4713,4736-4741,4754,4756-4771,4775,4777-4780,4782-4785,4795,4811-4820,4822-4824,4828-4832,4834,4840,4842-4844
\ No newline at end of property
Modified: branches/stable-1.2/src/http/modules/ngx_http_geo_module.c
===================================================================
--- branches/stable-1.2/src/http/modules/ngx_http_geo_module.c	2012-09-24 19:05:02 UTC (rev 4857)
+++ branches/stable-1.2/src/http/modules/ngx_http_geo_module.c	2012-09-24 19:06:48 UTC (rev 4858)
@@ -233,12 +233,21 @@
 #if (NGX_HAVE_INET6)
 
     if (addr.sockaddr->sa_family == AF_INET6) {
+        u_char           *p;
+        in_addr_t         inaddr;
         struct in6_addr  *inaddr6;
 
         inaddr6 = &((struct sockaddr_in6 *) addr.sockaddr)->sin6_addr;
 
         if (IN6_IS_ADDR_V4MAPPED(inaddr6)) {
-            return ntohl(*(in_addr_t *) &inaddr6->s6_addr[12]);
+            p = inaddr6->s6_addr;
+
+            inaddr = p[12] << 24;
+            inaddr += p[13] << 16;
+            inaddr += p[14] << 8;
+            inaddr += p[15];
+
+            return inaddr;
         }
     }
 

Modified: branches/stable-1.2/src/http/modules/ngx_http_geoip_module.c
===================================================================
--- branches/stable-1.2/src/http/modules/ngx_http_geoip_module.c	2012-09-24 19:05:02 UTC (rev 4857)
+++ branches/stable-1.2/src/http/modules/ngx_http_geoip_module.c	2012-09-24 19:06:48 UTC (rev 4858)
@@ -226,12 +226,21 @@
 #if (NGX_HAVE_INET6)
 
     if (addr.sockaddr->sa_family == AF_INET6) {
+        u_char           *p;
+        in_addr_t         inaddr;
         struct in6_addr  *inaddr6;
 
         inaddr6 = &((struct sockaddr_in6 *) addr.sockaddr)->sin6_addr;
 
         if (IN6_IS_ADDR_V4MAPPED(inaddr6)) {
-            return ntohl(*(in_addr_t *) &inaddr6->s6_addr[12]);
+            p = inaddr6->s6_addr;
+
+            inaddr = p[12] << 24;
+            inaddr += p[13] << 16;
+            inaddr += p[14] << 8;
+            inaddr += p[15];
+
+            return inaddr;
         }
     }
 

Modified: branches/stable-1.2/src/http/ngx_http_core_module.c
===================================================================
--- branches/stable-1.2/src/http/ngx_http_core_module.c	2012-09-24 19:05:02 UTC (rev 4857)
+++ branches/stable-1.2/src/http/ngx_http_core_module.c	2012-09-24 19:06:48 UTC (rev 4858)
@@ -2733,7 +2733,15 @@
 
         if (IN6_IS_ADDR_V4MAPPED(inaddr6)) {
             family = AF_INET;
-            inaddr = *(in_addr_t *) &inaddr6->s6_addr[12];
+
+            p = inaddr6->s6_addr;
+
+            inaddr = p[12] << 24;
+            inaddr += p[13] << 16;
+            inaddr += p[14] << 8;
+            inaddr += p[15];
+
+            inaddr = htonl(inaddr);
         }
     }
 #endif



More information about the nginx-devel mailing list