Skip to content

fix: off by one error in gsoSplit on linux - #140

Merged
encodeous merged 1 commit into
mainfrom
ac/wg-gsosplit-obo
Jul 25, 2026
Merged

fix: off by one error in gsoSplit on linux#140
encodeous merged 1 commit into
mainfrom
ac/wg-gsosplit-obo

Conversation

@encodeous

Copy link
Copy Markdown
Owner

WireGuard upstream seems to have an off-by-one error in the gsoSplit function.

A countercase would be if our outBuffs' size is 1.

if i == len(outBuffs) {
	return i - 1, ErrTooManySegments
}

Would return 0, while the fn is supposed to return "the number of buffers populated".

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an off-by-one bug in the Linux gsoSplit implementation so that, when the output buffer slice is exhausted, the function returns the correct “number of buffers populated” value (matching its documented contract). This aligns ErrTooManySegments behavior with how callers can safely use the returned count.

Changes:

  • Adjust gsoSplit overflow return value from i-1 to i to correctly report populated buffer count.
  • Add a regression test to validate the overflow behavior returns len(out) populated buffers alongside ErrTooManySegments.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
polyamide/tun/offload_linux.go Fixes overflow count returned by gsoSplit to match the “buffers populated” contract.
polyamide/tun/offload_linux_test.go Adds a targeted regression test ensuring overflow returns the populated count and ErrTooManySegments.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@encodeous
encodeous merged commit 0b70880 into main Jul 25, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants