]> git.ipfire.org Git - thirdparty/openvpn.git/commit
Don't deference type-punned pointers
authorSteffan Karger <steffan@karger.me>
Sun, 13 Nov 2016 13:17:27 +0000 (14:17 +0100)
committerGert Doering <gert@greenie.muc.de>
Sun, 13 Nov 2016 13:21:45 +0000 (14:21 +0100)
commit8cac9b98d58b97fbd5a23dd9f172a9843ecf5b50
tree330f69855fa58a0fd7f4ddb99a8b299d13a1171d
parent14cb1639f7694cdd461bace5e273acd7722cd3cf
Don't deference type-punned pointers

Dereferencing type-punned pointers is undefined behaviour according to the
C standard.  We should either obey the standard, or ensure that all
supported compilers deal with dereferencing type-punned pointers as we
want them to.  I think just obeying the standard is the easiest solution.

See e.g. http://blog.regehr.org/archives/959.

This commit refactors the offending code to use unions or memcpy() to
comply to strict aliasing rules.

Note that this also slightly changes mroute_addr_mask_host_bits(), to
behave as it was probably intended to:  only mask the address part, not
also the port part of IPv6 adresses if MR_WITH_PORT is used (ie ma->len
is sizeof(struct in6_addr)+2).

v2: fix all strict aliasing occurrences, not just those in mroute.h
v3: add missing ntohs() in mroute_addr_print_ex()

Signed-off-by: Steffan Karger <steffan@karger.me>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <1479043047-25883-1-git-send-email-steffan@karger.me>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg13017.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/error.h
src/openvpn/mroute.c
src/openvpn/mroute.h
src/openvpn/multi.c
src/openvpn/ps.c
src/openvpn/socket.c