Skip to content

Commit 8adee0c

Browse files
AdityaGarg8gitster
authored andcommitted
send-mail: improve checks for valid_fqdn
The current implementation of a valid Fully Qualified Domain Name is not that strict. It just checks whether it has a dot (.) and if using macOS, it should not end with .local. As per RFC1035[1], from what I understood, the following checks need to be done: - The domain must contain atleast one dot - Each label (separated by dots) must be 1-63 characters long - Labels must start and end with an alphanumeric character - Labels can contain alphanumeric characters and hyphens Here are some examples of valid and invalid labels: 'example.com', # Valid 'sub.example.com', # Valid 'my-domain.org', # Valid 'localhost', # Invalid (no dot) 'MacBook..', # Invalid (double dots) '-example.com', # Invalid (starts with a hyphen) 'example-.com', # Invalid (ends with a hyphen) 'example..com', # Invalid (double dots) 'example', # Invalid (no TLD) 'example.local', # Invalid on macOS 'valid-domain.co.uk', # Valid '123.example.com', # Valid 'example.com.', # Invalid (trailing dot) 'toolonglabeltoolonglabeltoolonglabeltoolonglabeltoolonglabeltoolonglabel.com', # Invalid (label > 63 chars) Due to current implementation, I was not able to send emails from Ubuntu. Upon debugging, I found that the SMTP domain being passed to Outlook's servers was not valid. Net::SMTP=GLOB(0x5db4351225f8)>>> EHLO MacBook.. Net::SMTP=GLOB(0x5db4351225f8)<<< 501 5.5.4 Invalid domain name Net::SMTP=GLOB(0x5db4351225f8)>>> HELO MacBook.. Notice that an invalid domain name "MacBook.." is sent by git-send-email. We have a fallback code that checks output from Net::Domain::domainname() or asking domain method of an Net::SMTP instance to detect a misconfigured hostname and replace it with fallback "localhost.localdomain", but the valid_fqdn apparently is failing to say "MacBook.." is not a valid fqdn. With this patch, the rule used in valid_fqdn is tightened, the beginning part of the SMTP exchange looked like this: Net::SMTP=GLOB(0x58c8af71e930)>>> EHLO localhost.localdomain Net::SMTP=GLOB(0x58c8af71e930)<<< 250-PN4P287CA0064.outlook.office365.com Hello [1]: https://datatracker.ietf.org/doc/html/rfc1035 Signed-off-by: Aditya Garg <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6f84262 commit 8adee0c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

git-send-email.perl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,9 @@ sub process_address_list {
13541354

13551355
sub valid_fqdn {
13561356
my $domain = shift;
1357-
return defined $domain && !($^O eq 'darwin' && $domain =~ /\.local$/) && $domain =~ /\./;
1357+
my $subdomain = '(?!-)[A-Za-z0-9-]{1,63}(?<!-)';
1358+
return defined $domain && !($^O eq 'darwin' && $domain =~ /\.local$/)
1359+
&& $domain =~ /^$subdomain(?:\.$subdomain)*$/;
13581360
}
13591361

13601362
sub maildomain_net {

0 commit comments

Comments
 (0)