mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-01 01:09:47 +00:00
HttpUtils.pm: close socket if DNS lookup fails (Forum #56435)
git-svn-id: https://svn.fhem.de/fhem/trunk@11928 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
a2d9245464
commit
fcb85299fe
@ -166,7 +166,7 @@ HttpUtils_gethostbyname($$$)
|
|||||||
my $buf;
|
my $buf;
|
||||||
my $len = sysread($dh{conn},$buf,65536);
|
my $len = sysread($dh{conn},$buf,65536);
|
||||||
HttpUtils_Close(\%dh);
|
HttpUtils_Close(\%dh);
|
||||||
Log 5, "DNS ANSWER $len:".unpack("H*", $buf);
|
Log 5, "DNS ANSWER ".($len?$len:0).":".($buf ? unpack("H*", $buf):"N/A");
|
||||||
my ($err, $addr, $ttl) = HttpUtils_dnsParse($buf,$ql);
|
my ($err, $addr, $ttl) = HttpUtils_dnsParse($buf,$ql);
|
||||||
return $fn->($hash, "DNS: $err", undef) if($err);
|
return $fn->($hash, "DNS: $err", undef) if($err);
|
||||||
Log 4, "DNS result for $host: ".ip2str($addr).", ttl:$ttl";
|
Log 4, "DNS result for $host: ".ip2str($addr).", ttl:$ttl";
|
||||||
@ -194,7 +194,6 @@ HttpUtils_gethostbyname($$$)
|
|||||||
InternalTimer(gettimeofday()+$dnsTo, $dnsQuery, \%timerHash);
|
InternalTimer(gettimeofday()+$dnsTo, $dnsQuery, \%timerHash);
|
||||||
};
|
};
|
||||||
$dnsQuery->();
|
$dnsQuery->();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -238,7 +237,10 @@ HttpUtils_Connect($)
|
|||||||
HttpUtils_gethostbyname($hash, $host, sub($$$) {
|
HttpUtils_gethostbyname($hash, $host, sub($$$) {
|
||||||
my ($hash, $err, $iaddr) = @_;
|
my ($hash, $err, $iaddr) = @_;
|
||||||
$hash = $hash->{origHash} if($hash->{origHash});
|
$hash = $hash->{origHash} if($hash->{origHash});
|
||||||
return $hash->{callback}($hash, $err, "") if($err);
|
if($err) {
|
||||||
|
HttpUtils_Close($hash);
|
||||||
|
return $hash->{callback}($hash, $err, "") ;
|
||||||
|
}
|
||||||
my $ret = connect($hash->{conn}, sockaddr_in($port, $iaddr));
|
my $ret = connect($hash->{conn}, sockaddr_in($port, $iaddr));
|
||||||
if(!$ret) {
|
if(!$ret) {
|
||||||
if($!{EINPROGRESS} || int($!)==10035 ||
|
if($!{EINPROGRESS} || int($!)==10035 ||
|
||||||
@ -254,8 +256,10 @@ HttpUtils_Connect($)
|
|||||||
RemoveInternalTimer(\%timerHash);
|
RemoveInternalTimer(\%timerHash);
|
||||||
my $packed = getsockopt($hash->{conn}, SOL_SOCKET, SO_ERROR);
|
my $packed = getsockopt($hash->{conn}, SOL_SOCKET, SO_ERROR);
|
||||||
my $errno = unpack("I",$packed);
|
my $errno = unpack("I",$packed);
|
||||||
return $hash->{callback}($hash, "$host: ".strerror($errno), "")
|
if($errno) {
|
||||||
if($errno);
|
HttpUtils_Close($hash);
|
||||||
|
return $hash->{callback}($hash, "$host: ".strerror($errno), "");
|
||||||
|
}
|
||||||
|
|
||||||
my $err = HttpUtils_Connect2($hash);
|
my $err = HttpUtils_Connect2($hash);
|
||||||
$hash->{callback}($hash, $err, "") if($err);
|
$hash->{callback}($hash, $err, "") if($err);
|
||||||
@ -266,9 +270,12 @@ HttpUtils_Connect($)
|
|||||||
InternalTimer(gettimeofday()+$hash->{timeout},
|
InternalTimer(gettimeofday()+$hash->{timeout},
|
||||||
"HttpUtils_Err", \%timerHash);
|
"HttpUtils_Err", \%timerHash);
|
||||||
return undef;
|
return undef;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
HttpUtils_Close($hash);
|
||||||
$hash->{callback}($hash, "connect to $hash->{addr}: $!", "");
|
$hash->{callback}($hash, "connect to $hash->{addr}: $!", "");
|
||||||
return undef;
|
return undef;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user