IcingaServiceForm: protect against branched objects

...w/o id. Can be improved
This commit is contained in:
Thomas Gelf 2022-09-20 12:19:53 +02:00
parent 4d2f285c01
commit 3c8bb6bd16

View File

@ -224,13 +224,19 @@ class IcingaServiceForm extends DirectorObjectForm
if ($this->blacklisted === null) {
$host = $this->host;
// Safety check, branches
$hostId = $host->get('id');
$service = $this->getServiceToBeBlacklisted();
$serviceId = $service->get('id');
if (! $hostId || ! $serviceId) {
return false;
}
$db = $this->db->getDbAdapter();
if ($this->providesOverrides()) {
$this->blacklisted = 1 === (int)$db->fetchOne(
$db->select()->from('icinga_host_service_blacklist', 'COUNT(*)')
->where('host_id = ?', $host->get('id'))
->where('service_id = ?', $service->get('id'))
->where('host_id = ?', $hostId)
->where('service_id = ?', $serviceId)
);
} else {
$this->blacklisted = false;