summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDan Fandrich <dan@coneharvesters.com>2023-04-17 16:52:53 -0700
committerDan Fandrich <dan@coneharvesters.com>2023-04-18 13:18:17 -0700
commit2e0b70b8bcfcc30c65caabbe5b84e17368dadf65 (patch)
treeb8ee9eb8bd97b82bd491b47f431484ec0cc41e70 /tests
parentb11840807bb805b2d8695f4957cf96d0fd4449f1 (diff)
downloadcurl-2e0b70b8bcfcc30c65caabbe5b84e17368dadf65.tar.gz
runtests: don't accidentally randomly choose the same port
If a server couldn't be started on a port, a new one is randomly chosen and the server is tried again. Avoid accidentally using a randomly-chosen 0 port offset by adding 1 to the random number. Found-by: Daniel Stenberg
Diffstat (limited to 'tests')
-rw-r--r--tests/servers.pm20
1 files changed, 10 insertions, 10 deletions
diff --git a/tests/servers.pm b/tests/servers.pm
index cc4a939c0..f877374b1 100644
--- a/tests/servers.pm
+++ b/tests/servers.pm
@@ -1204,8 +1204,8 @@ sub runhttp2server {
my $port2 = 23114;
my %usedports = reverse %PORT;
for(1 .. $serverstartretries) {
- $port += int(rand(900));
- $port2 += int(rand(900));
+ $port += 1 + int(rand(900));
+ $port2 += 1 + int(rand(900));
next if exists $usedports{$port} || $usedports{$port2};
my $aflags = "--port $port --port2 $port2 $flags";
@@ -1275,7 +1275,7 @@ sub runhttp3server {
my $port = 24113;
my %usedports = reverse %PORT;
for(1 .. $serverstartretries) {
- $port += int(rand(900));
+ $port += 1 + int(rand(900));
next if exists $usedports{$port};
my $aflags = "--port $port $flags";
@@ -1363,7 +1363,7 @@ sub runhttpsserver {
my $port = 24512; # start attempt
my %usedports = reverse %PORT;
for (1 .. $serverstartretries) {
- $port += int(rand(600));
+ $port += 1 + int(rand(600));
next if exists $usedports{$port};
my $options = "$flags --accept $port";
@@ -1432,7 +1432,7 @@ sub runhttptlsserver {
my %usedports = reverse %PORT;
my ($httptlspid, $pid2);
for (1 .. $serverstartretries) {
- $port += int(rand(800));
+ $port += 1 + int(rand(800));
next if exists $usedports{$port};
my $allflags = "--port $port $flags";
@@ -1583,7 +1583,7 @@ sub runsecureserver {
my $port = 26713 + ord $proto;
my %usedports = reverse %PORT;
for (1 .. $serverstartretries) {
- $port += int(rand(700));
+ $port += 1 + int(rand(700));
next if exists $usedports{$port};
my $options = "$flags --accept $port";
my $cmd = "$perl $srcdir/secureserver.pl $options";
@@ -1821,7 +1821,7 @@ sub runsshserver {
# sshd doesn't have a way to pick an unused random port number, so
# instead we iterate over possible port numbers to use until we find
# one that works
- $port += int(rand(500));
+ $port += 1 + int(rand(500));
next if exists $usedports{$port};
push @tports, $port;
@@ -2070,7 +2070,7 @@ sub rundictserver {
my %usedports = reverse %PORT;
my ($dictpid, $pid2);
for(1 .. $serverstartretries) {
- $port += int(rand(900));
+ $port += 1 + int(rand(900));
next if exists $usedports{$port};
my $aflags = "--port $port $flags";
my $cmd = "$srcdir/dictserver.py $aflags";
@@ -2138,7 +2138,7 @@ sub runsmbserver {
my $port = 31923;
my %usedports = reverse %PORT;
for(1 .. $serverstartretries) {
- $port += int(rand(760));
+ $port += 1 + int(rand(760));
next if exists $usedports{$port};
my $aflags = "--port $port $flags";
my $cmd = "$srcdir/smbserver.py $aflags";
@@ -2205,7 +2205,7 @@ sub runnegtelnetserver {
my $port = 32000;
my %usedports = reverse %PORT;
for(1 .. $serverstartretries) {
- $port += int(rand(800));
+ $port += 1 + int(rand(800));
next if exists $usedports{$port};
my $aflags = "--port $port $flags";
my $cmd = "$srcdir/negtelnetserver.py $aflags";