diff options
| author | Denys Fedoryshchenko <denys.f@collabora.com> | 2026-07-12 23:12:03 +0300 |
|---|---|---|
| committer | Denys Fedoryshchenko <denys.f@collabora.com> | 2026-07-12 23:12:03 +0300 |
| commit | efa4cea1beec1fa758ac94f350dfa7bdfa6d472f (patch) | |
| tree | 93d73d7c4727dc4858a645302f69c230260b3dda /accel-pppd/ipdb.c | |
| parent | 1c43c26d5c87df722141ad6a37f068968a9a6b5b (diff) | |
| download | accel-ppp-efa4cea1beec1fa758ac94f350dfa7bdfa6d472f.tar.gz accel-ppp-efa4cea1beec1fa758ac94f350dfa7bdfa6d472f.zip | |
ipdb: fix undefined shift in build_ip6_addr() host-bits mask
For prefix lengths 65..127 the mask for the host bits was built with
(1 << (128 - prefix_len)) - 1 using a plain int literal, which is
undefined behavior for shift counts of 31 and above, i.e. for any
prefix length from 65 to 97. Use a 64-bit constant for the shift.
Diffstat (limited to 'accel-pppd/ipdb.c')
| -rw-r--r-- | accel-pppd/ipdb.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/accel-pppd/ipdb.c b/accel-pppd/ipdb.c index dd8c61c9..8fc08063 100644 --- a/accel-pppd/ipdb.c +++ b/accel-pppd/ipdb.c @@ -83,7 +83,10 @@ void __export build_ip6_addr(struct ipv6db_addr_t *a, uint64_t intf_id, struct i if (a->prefix_len <= 64) *(uint64_t *)(addr->s6_addr + 8) = intf_id; else - *(uint64_t *)(addr->s6_addr + 8) |= intf_id & htobe64((1 << (128 - a->prefix_len)) - 1); + /* prefix_len 65..127 means a shift of up to 63 bits: a plain + * int literal 1 is undefined behavior for shifts >= 31, so the + * host bits mask must be built from a 64-bit constant */ + *(uint64_t *)(addr->s6_addr + 8) |= intf_id & htobe64((UINT64_C(1) << (128 - a->prefix_len)) - 1); } |
