From: Willy Tarreau Date: Thu, 20 Sep 2018 08:48:35 +0000 (+0200) Subject: BUG/MINOR: tools: fix set_net_port() / set_host_port() on IPv4 X-Git-Tag: v1.9-dev3~23 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4c0fcc2314f746b05bd5a613f188784761dc9ac9;p=thirdparty%2Fhaproxy.git BUG/MINOR: tools: fix set_net_port() / set_host_port() on IPv4 These two functions were apparently written on the same model as their parents when added by commit 11bcb6c4f ("[MEDIUM] IPv6 support for syslog") except that they perform an assignment instead of a return, and as a result fall through the next case where the assigned value may possibly be partially overwritten. At least under Linux the port offset is the same in both sockaddr_in and sockaddr_in6 so the value is written twice without side effects. This needs to be backported as far as 1.5. --- diff --git a/include/common/standard.h b/include/common/standard.h index ad1a767481..5c7d15229e 100644 --- a/include/common/standard.h +++ b/include/common/standard.h @@ -1007,8 +1007,10 @@ static inline int set_net_port(struct sockaddr_storage *addr, int port) switch (addr->ss_family) { case AF_INET: ((struct sockaddr_in *)addr)->sin_port = port; + break; case AF_INET6: ((struct sockaddr_in6 *)addr)->sin6_port = port; + break; } return 0; } @@ -1019,8 +1021,10 @@ static inline int set_host_port(struct sockaddr_storage *addr, int port) switch (addr->ss_family) { case AF_INET: ((struct sockaddr_in *)addr)->sin_port = htons(port); + break; case AF_INET6: ((struct sockaddr_in6 *)addr)->sin6_port = htons(port); + break; } return 0; }