Perl-Email-Project / Email-Valid

perl library to validate email addresses
19 stars 19 forks source link

Use of uninitialized value $tld in hash element #38

Open AlessandroGorohovski opened 7 years ago

AlessandroGorohovski commented 7 years ago

Dear Ricardo,

I found that Email::Valid->address( -address => 'guest@xn--c1ad6a.xn--p1ai', -tldcheck => 1 ); causes warnings in Email::Valid.pm module:

Use of uninitialized value $tld in hash element at /usr/local/share/perl/5.18.2/Email/Valid.pm line 234. Use of uninitialized value $_[0] in lc at /usr/local/share/perl/5.18.2/Net/Domain/TLD.pm line 2033.

I think the problem with line 234:

$ head -n 234 Valid.pm | tail -n 5

  1. my ($tld) = $host =~ m#.(\w+)$#;
  2. my %invalidtlds = map { $ => 1 } qw(invalid test example localhost);
  3. return defined $invalid_tlds{$tld} ? 0 : Net::Domain::TLD::tld_exists($tld);

due to lack of undef control after my ($tld) = $host =~ m#.(\w+)$#.

Regards, Alessandro

lechner commented 5 years ago

I have this problem, too, using Email::Valid->tld on Debian testing:

perl -MEmail::Valid -e 'Email::Valid->tld(q{unknown@unknown})'
Use of uninitialized value $tld in hash element at /usr/share/perl5/Email/Valid.pm line 234.
Use of uninitialized value $_[0] in lc at /usr/share/perl5/Net/Domain/TLD.pm line 2033.

Perhaps return 0 unless defined $tld; or $tld //= q{}; would be appropriate before using the value.