Skip to content

src: Fix division by zero in UDP bandwidth calculation in iperf_api.c#1906

Merged
bmah888 merged 1 commit intoesnet:masterfrom
AntonMoryakov:DIVISION_BY_ZERO.EX.FLOAT-iperf_api.c
Aug 1, 2025
Merged

src: Fix division by zero in UDP bandwidth calculation in iperf_api.c#1906
bmah888 merged 1 commit intoesnet:masterfrom
AntonMoryakov:DIVISION_BY_ZERO.EX.FLOAT-iperf_api.c

Conversation

@AntonMoryakov
Copy link
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

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

    • In iperf_api.c, variables sender_time and receiver_time were used as denominators in bandwidth calculations without a zero check, which could lead to division by zero and undefined behavior.
    • To fix this, introduced sent_bandwidth and recv_bandwidth variables with a conditional check to prevent division by zero. If time is zero, bandwidth is now safely set to 0.0.

In iperf_api.c, variables sender_time and receiver_time were used as
denominators in bandwidth calculations without a zero check, which could
lead to division by zero and undefined behavior.

To fix this, introduced sent_bandwidth and recv_bandwidth variables with
a conditional check to prevent division by zero. If time is zero,
bandwidth is now safely set to 0.0.

Signed-off-by: Anton Moryakov <[email protected]>
Copy link
Contributor

@bmah888 bmah888 left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks for the PR!

@bmah888 bmah888 merged commit b9371bf into esnet:master Aug 1, 2025
6 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