Skip to content

fix(iperf3): bound the results JSON_read to reject an oversized length - #44

Merged
Frostman merged 1 commit into
masterfrom
pau/bound-iperf3-results-json-read
Aug 31, 2026
Merged

fix(iperf3): bound the results JSON_read to reject an oversized length#44
Frostman merged 1 commit into
masterfrom
pau/bound-iperf3-results-json-read

Conversation

@pau-hedgehog

@pau-hedgehog pau-hedgehog commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

get_results in iperf3's src/iperf_api.c passed 0 as max_size to JSON_read, disabling its size check. A server abort mid-results-exchange writes the control-channel SERVER_ERROR state byte, 0xFE, which a client already blocked in get_results misreads as the high byte of a length, exactly 0xFE000000 (3.97 GiB). On the ~700 MB VMs fabricator's release-test runs on, that calloc is refused and the client reports Cannot allocate memory instead of the server's real error, discussed in detail in #43 and githedgehog/fabricator#1746.

This patches the get_results call site to pass a 1 MiB bound, the same treatment the params-read call site a few hundred lines earlier in the same file already gets with MAX_PARAMS_JSON_STRING (8 KB). 1 MiB comfortably covers a results JSON for iperf3's max of 128 streams while staying far below the corrupted 0xFE000000 length, so it rejects the corruption without risking a legitimate result. The sed is anchored to the exact current line and followed by a grep -q that fails the build if it doesn't match, so a future upstream bump either carries the patch or breaks the build loudly instead of silently reverting to unbounded.

Validation:

  • Built the image locally (docker build --target builder) and confirmed the grep guard passes, meaning the sed matched.
  • Ran a real iperf3 client/server pair from the patched image, bidir, 4 streams, and confirmed get_results still parses a legitimate result under the new 1 MiB bound (full JSON output, no error field).

Fixes #43

get_results passed 0 as max_size, so a server SERVER_ERROR byte
misread as a length went straight to calloc instead of being
rejected, masking the real server-side error as ENOMEM on the
client.

Fixes #43

Signed-off-by: Pau Capdevila <pau@githedgehog.com>
@github-actions

Copy link
Copy Markdown

🚀 Temp artifacts published: v0-83cb81560 🚀

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

Bounds iperf3’s client-side results JSON read during image build to prevent a corrupted/aborted control-channel exchange from being interpreted as a multi‑GiB JSON length and triggering misleading ENOMEM errors.

Changes:

  • Patch iperf3 3.21 at build time to call JSON_read(test->ctrl_sck, 1024 * 1024) instead of unbounded JSON_read(..., 0) for results.
  • Add a build-time grep guard to ensure the sed-based patch is applied (or fail loudly if upstream changes).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Frostman

Copy link
Copy Markdown
Member

@pau-hedgehog is there a fix or bug in upstream? If not we should file and contribute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants