aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruce A. Mah <bmah@es.net>2019-06-14 11:21:15 -0700
committerGitHub <noreply@github.com>2019-06-14 11:21:15 -0700
commit6c7834629a5677802720a2efe496763f55bee269 (patch)
tree08057fc936acee8660ae16b10341e127dc7b55d2 /src
parent255a9c71109406f23ebf9d651ca3f265aa1058f5 (diff)
downloadiperf3-6c7834629a5677802720a2efe496763f55bee269.tar.gz
Fix: Don't allow --port 0 or other invalid values. (#885)
* Fix: Don't allow --port or --cport to take 0 or other invalid values. Fixes #884.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/iperf_api.c17
-rwxr-xr-xsrc/iperf_api.h3
-rw-r--r--src/iperf_error.c5
3 files changed, 20 insertions, 5 deletions
diff --git a/src/iperf_api.c b/src/iperf_api.c
index 4e8ed1f..a6a594e 100755
--- a/src/iperf_api.c
+++ b/src/iperf_api.c
@@ -1,5 +1,5 @@
/*
- * iperf, Copyright (c) 2014-2018, The Regents of the University of
+ * iperf, Copyright (c) 2014-2019, The Regents of the University of
* California, through Lawrence Berkeley National Laboratory (subject
* to receipt of any required approvals from the U.S. Dept. of
* Energy). All rights reserved.
@@ -842,6 +842,7 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
{NULL, 0, NULL, 0}
};
int flag;
+ int portno;
int blksize;
int server_flag, client_flag, rate_flag, duration_flag;
char *endptr;
@@ -861,7 +862,12 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
while ((flag = getopt_long(argc, argv, "p:f:i:D1VJvsc:ub:t:n:k:l:P:Rw:B:M:N46S:L:ZO:F:A:T:C:dI:hX:", longopts, NULL)) != -1) {
switch (flag) {
case 'p':
- test->server_port = atoi(optarg);
+ portno = atoi(optarg);
+ if (portno < 1 || portno > 65535) {
+ i_errno = IEBADPORT;
+ return -1;
+ }
+ test->server_port = portno;
break;
case 'f':
if (!optarg) {
@@ -1025,7 +1031,12 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
test->bind_address = strdup(optarg);
break;
case OPT_CLIENT_PORT:
- test->bind_port = atoi(optarg);
+ portno = atoi(optarg);
+ if (portno < 1 || portno > 65535) {
+ i_errno = IEBADPORT;
+ return -1;
+ }
+ test->bind_port = portno;
break;
case 'M':
test->settings->mss = atoi(optarg);
diff --git a/src/iperf_api.h b/src/iperf_api.h
index 7483faa..f9f964e 100755
--- a/src/iperf_api.h
+++ b/src/iperf_api.h
@@ -1,5 +1,5 @@
/*
- * iperf, Copyright (c) 2014-2018, The Regents of the University of
+ * iperf, Copyright (c) 2014-2019, The Regents of the University of
* California, through Lawrence Berkeley National Laboratory (subject
* to receipt of any required approvals from the U.S. Dept. of
* Energy). All rights reserved.
@@ -342,6 +342,7 @@ enum {
IESETSERVERAUTH = 23, // Bad configuration of server authentication
IEBADFORMAT = 24, // Bad format argument to -f
IEREVERSEBIDIR = 25, // Iperf cannot be both reverse and bidirectional
+ IEBADPORT = 26, // Bad port number
/* Test errors */
IENEWTEST = 100, // Unable to create a new test (check perror)
IEINITTEST = 101, // Test initialization failed (check perror)
diff --git a/src/iperf_error.c b/src/iperf_error.c
index 3d34b63..e6eb032 100644
--- a/src/iperf_error.c
+++ b/src/iperf_error.c
@@ -1,5 +1,5 @@
/*
- * iperf, Copyright (c) 2014-2018, The Regents of the University of
+ * iperf, Copyright (c) 2014-2019, The Regents of the University of
* California, through Lawrence Berkeley National Laboratory (subject
* to receipt of any required approvals from the U.S. Dept. of
* Energy). All rights reserved.
@@ -140,6 +140,9 @@ iperf_strerror(int int_errno)
case IEBADFORMAT:
snprintf(errstr, len, "bad format specifier (valid formats are in the set [kmgtKMGT])");
break;
+ case IEBADPORT:
+ snprintf(errstr, len, "port number must be between 1 and 65535 inclusive");
+ break;
case IEMSS:
snprintf(errstr, len, "TCP MSS too large (maximum = %d bytes)", MAX_MSS);
break;