Catch bad DNS queries and reduce exception logging

This commit is contained in:
Deon George 2023-10-04 15:50:24 +11:00
parent 0fcb628c11
commit d82f8ac8b3
2 changed files with 11 additions and 5 deletions

View File

@ -104,8 +104,15 @@ final class DNS extends BaseProtocol
{ {
Log::debug(sprintf('%s:+ DNS Query',self::LOGKEY)); Log::debug(sprintf('%s:+ DNS Query',self::LOGKEY));
try {
$this->query = new BaseProtocol\DNS\Query($this->client->read(0,512)); $this->query = new BaseProtocol\DNS\Query($this->client->read(0,512));
} catch (\Exception $e) {
Log::error(sprintf('%s:! Ignoring bad DNS query (%s)',self::LOGKEY,$e->getMessage()));
return FALSE;
}
Log::info(sprintf('%s:= DNS Query from [%s] for [%s]',self::LOGKEY,$this->client->address_remote,$this->query->domain)); Log::info(sprintf('%s:= DNS Query from [%s] for [%s]',self::LOGKEY,$this->client->address_remote,$this->query->domain));
// If the wrong class // If the wrong class

View File

@ -61,7 +61,7 @@ final class Query
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error(sprintf('%s:! Unpack failed: Buffer: [%s] (%d), RXPTR [%d]',self::LOGKEY,hex_dump($this->buf),strlen($this->buf),$rx_ptr)); Log::error(sprintf('%s:! Unpack failed: Buffer: [%s] (%d), RXPTR [%d]',self::LOGKEY,hex_dump($this->buf),strlen($this->buf),$rx_ptr));
return; throw $e;
} }
$rx_ptr += 4; $rx_ptr += 4;
@ -82,9 +82,8 @@ final class Query
$rx_ptr += $this->additional->length; $rx_ptr += $this->additional->length;
} }
if (strlen($this->buf) !== $rx_ptr) { if (strlen($this->buf) !== $rx_ptr)
dd(['query remaining'=>strlen($this->buf)-$rx_ptr,'hex'=>hex_dump(substr($this->buf,$rx_ptr))]); throw new \Exception(sprintf('! DNS Buffer still has [%d]: %s',strlen($this->buf)-$rx_ptr,hex_dump(substr($this->buf,$rx_ptr))));
}
} }
public function __get($key) public function __get($key)