From: Thierry FOURNIER Date: Thu, 28 Nov 2013 15:33:15 +0000 (+0100) Subject: BUG/MEDIUM: sample: The function v4tov6 cannot support input and output overlap X-Git-Tag: v1.5-dev20~205 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4a04dc368dea3c2c2be2b30bdd6e7a8de4788f04;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: sample: The function v4tov6 cannot support input and output overlap 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. --- diff --git a/src/standard.c b/src/standard.c index b519f5716c..9f7f939fd8 100644 --- a/src/standard.c +++ b/src/standard.c @@ -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.