[PR #248] fix: avoid undefined shift for /0 bogus endpoint prefixes #260

Open
opened 2026-10-13 21:08:05 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/amnezia-vpn/amneziawg-linux-kernel-module/pull/248
Author: @HeisLuka
Created: 9/14/2026
Status: 🔄 Open

Base: master ← Head: fix/bogus-endpoints-prefix-zero-shift


📝 Commits (1)

  • 0e47b5f fix: avoid undefined IPv4 prefix shift

📊 Changes

1 file changed (+1 additions, -6 deletions)

View changed files

📝 src/netlink.c (+1 -6)

📄 Description

Summary

Avoid an undefined 32-bit shift when generating a bogus IPv4 endpoint for a /0 prefix.

generate_ipv4_address_with_prefix() currently computes the suffix mask using a 32-bit 1U. When prefix_len == 0, this becomes 1U << 32, which is undefined for a 32-bit unsigned int.

This change computes the mask in 64 bits and then narrows it back to u32.

suffix_mask = (u32)((1ULL << (32 - prefix->prefix_len)) - 1);

The existing validation already limits prefix_len to the range 0..32, so the 64-bit shift is always valid.

For /0, the resulting suffix mask is 0xffffffff. Prefixes from /1 through /32 keep their existing behavior.

This fixes the bogus_endpoints issue that was previously included in the closed #189, without bringing in that PR's unrelated cookie-reply change.

Scope

Only the optional IPv4 bogus_endpoints prefix generation path is changed.

The feature remains disabled by default.

Related to #189


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/amnezia-vpn/amneziawg-linux-kernel-module/pull/248 **Author:** [@HeisLuka](https://github.com/HeisLuka) **Created:** 9/14/2026 **Status:** 🔄 Open **Base:** `master` ← **Head:** `fix/bogus-endpoints-prefix-zero-shift` --- ### 📝 Commits (1) - [`0e47b5f`](https://github.com/amnezia-vpn/amneziawg-linux-kernel-module/commit/0e47b5fefe1b52d49c874186afce3509f671799d) fix: avoid undefined IPv4 prefix shift ### 📊 Changes **1 file changed** (+1 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `src/netlink.c` (+1 -6) </details> ### 📄 Description ## Summary Avoid an undefined 32-bit shift when generating a bogus IPv4 endpoint for a `/0` prefix. `generate_ipv4_address_with_prefix()` currently computes the suffix mask using a 32-bit `1U`. When `prefix_len == 0`, this becomes `1U << 32`, which is undefined for a 32-bit `unsigned int`. This change computes the mask in 64 bits and then narrows it back to `u32`. ```c suffix_mask = (u32)((1ULL << (32 - prefix->prefix_len)) - 1); ``` The existing validation already limits `prefix_len` to the range `0..32`, so the 64-bit shift is always valid. For `/0`, the resulting suffix mask is `0xffffffff`. Prefixes from `/1` through `/32` keep their existing behavior. This fixes the `bogus_endpoints` issue that was previously included in the closed #189, without bringing in that PR's unrelated cookie-reply change. ## Scope Only the optional IPv4 `bogus_endpoints` prefix generation path is changed. The feature remains disabled by default. Related to #189 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
amnezia-vpn/amneziawg-linux-kernel-module#260
No description provided.