mirror of
https://git.proxmox.com/git/pve-http-server
synced 2025-07-04 15:45:54 +00:00
accept-phase: shutdown socket on early error
if an error happens before AnyEvent::Handle registers the cleanup callback, we should shutdown/close the socket, when handling it. Using close, instead of shutdown($sock, SHUT_WR) here, since we are in an error-state, and would not read from the socket anyways. (Additionally close sends just on packet (RST,ACK), vs shutdown (FIN,ACK+RST,ACK) in its use here). Co-Authored-by: Dominik Csapak <d.csapak@proxmox.com> Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
This commit is contained in:
parent
c82d1707ed
commit
ebcaaf4606
@ -1532,6 +1532,11 @@ sub check_host_access {
|
|||||||
|
|
||||||
my $cip = Net::IP->new($clientip);
|
my $cip = Net::IP->new($clientip);
|
||||||
|
|
||||||
|
if (!$cip) {
|
||||||
|
$self->dprint("client IP not parsable: $@");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
my $match_allow = 0;
|
my $match_allow = 0;
|
||||||
my $match_deny = 0;
|
my $match_deny = 0;
|
||||||
|
|
||||||
@ -1564,10 +1569,10 @@ sub check_host_access {
|
|||||||
sub accept_connections {
|
sub accept_connections {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
my $handle_creation;
|
my ($clientfh, $handle_creation);
|
||||||
eval {
|
eval {
|
||||||
|
|
||||||
while (my $clientfh = $self->accept()) {
|
while ($clientfh = $self->accept()) {
|
||||||
|
|
||||||
my $reqstate = { keep_alive => $self->{keep_alive} };
|
my $reqstate = { keep_alive => $self->{keep_alive} };
|
||||||
|
|
||||||
@ -1579,12 +1584,16 @@ sub accept_connections {
|
|||||||
if (my $sin = getpeername($clientfh)) {
|
if (my $sin = getpeername($clientfh)) {
|
||||||
my ($pfamily, $pport, $phost) = PVE::Tools::unpack_sockaddr_in46($sin);
|
my ($pfamily, $pport, $phost) = PVE::Tools::unpack_sockaddr_in46($sin);
|
||||||
($reqstate->{peer_port}, $reqstate->{peer_host}) = ($pport, Socket::inet_ntop($pfamily, $phost));
|
($reqstate->{peer_port}, $reqstate->{peer_host}) = ($pport, Socket::inet_ntop($pfamily, $phost));
|
||||||
|
} else {
|
||||||
|
close($clientfh);
|
||||||
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$self->{trusted_env} && !$self->check_host_access($reqstate->{peer_host})) {
|
if (!$self->{trusted_env} && !$self->check_host_access($reqstate->{peer_host})) {
|
||||||
$self->dprint("ABORT request from $reqstate->{peer_host} - access denied");
|
$self->dprint("ABORT request from $reqstate->{peer_host} - access denied");
|
||||||
$reqstate->{log}->{code} = 403;
|
$reqstate->{log}->{code} = 403;
|
||||||
$self->log_request($reqstate);
|
$self->log_request($reqstate);
|
||||||
|
close($clientfh);
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1625,6 +1634,7 @@ sub accept_connections {
|
|||||||
|
|
||||||
if (my $err = $@) {
|
if (my $err = $@) {
|
||||||
syslog('err', $err);
|
syslog('err', $err);
|
||||||
|
close($clientfh);
|
||||||
if ($handle_creation) {
|
if ($handle_creation) {
|
||||||
if ($self->{conn_count} <= 0) {
|
if ($self->{conn_count} <= 0) {
|
||||||
warn "connection count <= 0 not decrementing!\n";
|
warn "connection count <= 0 not decrementing!\n";
|
||||||
|
Loading…
Reference in New Issue
Block a user