Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error handling to the unit_atoX() functions #1394

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jtdor
Copy link
Contributor

@jtdor jtdor commented Sep 21, 2022

  • 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):

Hi there,

I added an error handling to the unit_atoX() functions here when parsing commandline arguments.

src/units.c needs to include the large iperf_api.h now for i_errno only. It could be cleaner to factor out the declarations of i_errno and related functions to an iperf_error.h instead to reduce the coupling here. I could change that, if preferred?

Citing the commit for more description of the change:

Previously, the unit_atoX() functions did not have any error handling: Calling e.g. iperf3 -nZ -c ... would silently hide the fact that -n requires a numeric argument and also not apply the -Z (it was “consumed” by unit_atoi()). The intention was to pass -NZ here.

With this change, iperf3 will refuse options where unit_atoX() did not find any numeric value or detect an invalid suffix (not one of KMGT). For example:

user@host:~$ iperf3 -nZ -c ...
iperf3: parameter error - invalid unit value or suffix: 'Z'

Usage: iperf3 [-s|-c host] [options]
Try `iperf3 --help' for more information.

jtdor added 2 commits May 5, 2023 08:14
Previously, the unit_atoX() functions did not have any error handling:
Calling e.g. `iperf3 -nZ -c ...` would silently hide the fact that -n
requires a numeric argument and also not apply the -Z (it was “consumed”
by unit_atoi()). The intention was to pass -NZ here.

With this change, iperf3 will refuse options where unit_atoX() did not
find any numeric value or detect an invalid suffix (not one of KMGT).
@jtdor jtdor force-pushed the validate-numeric-arguments-are-numeric branch from 14babf7 to 923d9bf Compare May 5, 2023 06:20
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.

1 participant