From: Kirill Isakov Date: Sun, 15 Aug 2021 17:25:04 +0000 (+0600) Subject: Fix UBSAN warnings about conversions and overflows. X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=commitdiff_plain;h=04d8a8e34e1fe7f33f1946863b36a24ee358175f Fix UBSAN warnings about conversions and overflows. --- diff --git a/src/route.c b/src/route.c index 26a8aabc..69d0ba74 100644 --- a/src/route.c +++ b/src/route.c @@ -485,7 +485,7 @@ static void clamp_mss(const node_t *source, const node_t *via, vpn_packet_t *pac csum += csum >> 16; csum ^= 0xffff; DATA(packet)[start + 16] = csum >> 8; - DATA(packet)[start + 17] = csum; + DATA(packet)[start + 17] = csum & 0xff; break; } } diff --git a/src/subnet.c b/src/subnet.c index 602177ff..17dd39e8 100644 --- a/src/subnet.c +++ b/src/subnet.c @@ -83,7 +83,7 @@ static uint32_t hash_function_ipv6_t(const ipv6_t *p) { uint32_t hash = hash_seed; for(int i = 0; i < 4; i++) { - hash += fullwidth[i]; + hash = wrapping_add32(hash, fullwidth[i]); hash = wrapping_mul32(hash, 0x9e370001U); } @@ -95,7 +95,7 @@ static uint32_t hash_function_mac_t(const mac_t *p) { uint32_t hash = hash_seed; for(int i = 0; i < 3; i++) { - hash += halfwidth[i]; + hash = wrapping_add32(hash, halfwidth[i]); hash = wrapping_mul32(hash, 0x9e370001U); }