Skip to content

Fix UBSan with -i0: avoid division by zero - #2002

Merged
bmah888 merged 1 commit into
esnet:masterfrom
jackyyf:master
Mar 6, 2026
Merged

Fix UBSan with -i0: avoid division by zero#2002
bmah888 merged 1 commit into
esnet:masterfrom
jackyyf:master

Conversation

@jackyyf

@jackyyf jackyyf commented Feb 9, 2026

Copy link
Copy Markdown
Contributor

PLEASE NOTE the following text from the iperf3 license. Submitting a
pull request to the iperf3 repository constitutes "[making]
Enhancements available...publicly":

You are under no obligation whatsoever to provide any bug fixes, patches, or
upgrades to the features, functionality or performance of the source code
("Enhancements") to anyone; however, if you choose to make your Enhancements
available either publicly, or directly to Lawrence Berkeley National
Laboratory, without imposing a separate written license agreement for such
Enhancements, then you hereby grant the following license: a non-exclusive,
royalty-free perpetual license to install, use, modify, prepare derivative
works, incorporate into other computer software, distribute, and sublicense
such enhancements or derivative works thereof, in binary and source code form.

The complete iperf3 license is available in the LICENSE file in the
top directory of the iperf3 source tree.

  • Version of iperf3 (or development branch, such as master or
    3.1-STABLE) to which this pull request applies: master

  • Issues fixed (if any):

  • Brief description of code changes (suitable for use as a commit message):

Fix UBSan with `-i0`: avoid division by zero

The interval is explicity allowed to be zero, but we are trying to
divide by the interval without checking if it's zero, which will cause
an UBSan failure.

This commit fixed the issue by verify the interval is not zero before
division.
  • Actual UBSan report:
iperf3/src/iperf_api.c:1962:6: runtime error: inf is outside the range of representable values of type 'int'
    #0 0x555b386f6125 in iperf_parse_arguments iperf3/src/iperf_api.c:1962:6
    #1 0x555b386ef30a in main iperf3/src/main.c:117:9
<snip>

SUMMARY: UndefinedBehaviorSanitizer: float-cast-overflow iperf3/src/iperf_api.c:1962:6

The interval is explicity allowed to be zero, but we are trying to
divide by the interval without checking if it's zero, which will cause
an UBSan failure.

This commit fixed the issue by verify the interval is not zero before
division.
@jackyyf

jackyyf commented Feb 9, 2026

Copy link
Copy Markdown
Contributor Author

Sorry, forgot to include the command line used:

iperf3 -clocalhost -i0

and iperf3 will fail when compiled with -fsanitize=float-cast-overflow

@bmah888

bmah888 commented Feb 21, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR!

Quick test note: Configure iperf3 and then do something like this to get the C compiler flags (looks like this on macOS):

bmah@dock2 iperf % grep CFLAGS Makefile
CFLAGS = -g -O2 -Wall -pthread
PTHREAD_CFLAGS = -pthread

Then build with an extra argument in CFLAGS like this:

bmah@dock2 iperf % make CFLAGS="-g -O2 -Wall -pthread -fsanitize=float-cast-overflow"

THen run iperf3 like so:

src/iperf3 -c localhost -i0

@bmah888 bmah888 self-assigned this Feb 21, 2026
@bmah888 bmah888 added the bug label Feb 21, 2026

@bmah888 bmah888 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR! Just one minor suggestion.

Comment thread src/iperf_api.c
@bmah888
bmah888 merged commit 63cc9cc into esnet:master Mar 6, 2026
7 checks passed
@jackyyf

jackyyf commented Mar 6, 2026

Copy link
Copy Markdown
Contributor Author

Oops, super sorry for missing the comment, as the email slipped through my inbox queue. Please fix them in a later commit, sorry again for the incident

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants