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.
Этот коммит содержится в:
родитель
255a9c7110
Коммит
6c7834629a
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user