iperf icon indicating copy to clipboard operation
iperf copied to clipboard

Add error handling to the unit_atoX() functions

Open jtdor opened this issue 3 years ago • 0 comments

  • 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 avatar Sep 21 '22 10:09 jtdor