next;
}
if (defined $nentry->{port}) {
- if ($nentry->{port} =~ m/^\d+$/) {
- $num_port = $nentry->{port};
- delete $nentry->{port};
- } else {
+ $num_port = Git::port_num($nentry->{port});
+ unless ($num_port) {
printf(STDERR "ignoring invalid port `%s' " .
"from netrc file\n", $nentry->{port});
}
+ # Since we've already validated and converted
+ # the port to its numerical value, do not
+ # capture it as the `protocol' value, as used
+ # to be the case for symbolic port names.
+ delete $nentry->{port};
}
# create the new entry for the credential helper protocol
diag "Testing with invalid data\n";
$cred = run_credential(['-f', $netrc, 'get'],
"bad data");
-ok(scalar keys %$cred == 4, "Got first found keys with bad data");
+ok(scalar keys %$cred == 3, "Got first found keys with bad data");
diag "Testing netrc file for a missing corovamilkbar entry\n";
$cred = run_credential(['-f', $netrc, 'get'],
diag "Testing netrc file for a username-specific entry\n";
$cred = run_credential(['-f', $netrc, 'get'],
- { host => 'imap', username => 'bob' });
+ { host => 'imap:993', username => 'bob' });
-ok(scalar keys %$cred == 2, "Got 2 username-specific keys");
+# Only the password field gets returned.
+ok(scalar keys %$cred == 1, "Got 1 username-specific keys");
is($cred->{password}, 'bobwillknow', "Got correct user-specific password");
-is($cred->{protocol}, 'imaps', "Got correct user-specific protocol");
diag "Testing netrc file for a host:port-specific entry\n";
$cred = run_credential(['-f', $netrc, 'get'],
}
}
+ # Validate the SMTP server port, if provided.
+ if (defined $smtp_server_port) {
+ my $port = Git::port_num($smtp_server_port);
+ if ($port) {
+ $smtp_server_port = $port;
+ } else {
+ die sprintf(__("error: invalid SMTP port '%s'\n"),
+ $smtp_server_port);
+ }
+ }
+
# Run the loop once again to avoid gaps in the counter due to FIFO
# arguments provided by the user.
my $num = 1;
delete @$self{@vars};
}
+# Given PORT, a port number or service name, return its numerical
+# value else undef.
+sub port_num {
+ my ($port) = @_;
+
+ # Port can be either a positive integer within the 16-bit range...
+ if ($port =~ /^\d+$/ && $port > 0 && $port <= (2**16 - 1)) {
+ return $port;
+ }
+
+ # ... or a symbolic port (service name).
+ return scalar getservbyname($port, '');
+}
=item credential_read( FILEHANDLE )
test_cmp expected-cc commandline1
'
+test_expect_failure $PREREQ 'invalid smtp server port value' '
+ clean_fake_sendmail &&
+ git send-email -1 --to=recipient@example.com \
+ --smtp-server-port=bogus-symbolic-name \
+ --smtp-server="$(pwd)/fake.sendmail"
+'
+
test_expect_success $PREREQ 'setup expect' "
cat >expected-show-all-headers <<\EOF
0001-Second.patch