]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: sample: The function v4tov6 cannot support input and output overlap
authorThierry FOURNIER <tfournier@exceliance.fr>
Thu, 28 Nov 2013 15:33:15 +0000 (16:33 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 28 Nov 2013 16:09:45 +0000 (17:09 +0100)
This patch permits to use v4tov6 with the same input and output buffer. It
might have impacted the format of IPv4 addresses stored into IPv6 tables.

src/standard.c

index b519f5716c0226ab729ad2abd4350f3e17b23a72..9f7f939fd860fecc967ca7306fecd2d263de3b24 100644 (file)
@@ -1700,11 +1700,16 @@ const char rfc4291_pfx[] = { 0x00, 0x00, 0x00, 0x00,
                             0x00, 0x00, 0x00, 0x00,
                             0x00, 0x00, 0xFF, 0xFF };
 
-/* Map IPv4 adress on IPv6 address, as specified in RFC 3513. */
+/* Map IPv4 adress on IPv6 address, as specified in RFC 3513.
+ * Input and output may overlap.
+ */
 void v4tov6(struct in6_addr *sin6_addr, struct in_addr *sin_addr)
 {
+       struct in_addr tmp_addr;
+
+       tmp_addr.s_addr = sin_addr->s_addr;
        memcpy(sin6_addr->s6_addr, rfc4291_pfx, sizeof(rfc4291_pfx));
-       memcpy(sin6_addr->s6_addr+12, &sin_addr->s_addr, 4);
+       memcpy(sin6_addr->s6_addr+12, &tmp_addr.s_addr, 4);
 }
 
 /* Map IPv6 adress on IPv4 address, as specified in RFC 3513.