From 394ff7755b94779465472bb7b2189e5e210fe197 Mon Sep 17 00:00:00 2001 From: Valentin Hristov Date: Fri, 20 Mar 2020 12:16:21 +0200 Subject: [PATCH 01/17] fix(api): Resource::list return empty list if the regex is not valid Resolve MON-5034 --- .../Controller/MonitoringResourceController.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Centreon/Application/Controller/MonitoringResourceController.php b/src/Centreon/Application/Controller/MonitoringResourceController.php index e8b96b00654..50a07ffd748 100644 --- a/src/Centreon/Application/Controller/MonitoringResourceController.php +++ b/src/Centreon/Application/Controller/MonitoringResourceController.php @@ -140,8 +140,17 @@ public function list( $context->addExclusionStrategy(new ResourceExclusionStrategy()); - $resources = $this->resource->filterByContact($this->getUser()) - ->findResources($filter); + // try to avoid exception from the regexp bad syntax in search criteria + try { + $resources = $this->resource->filterByContact($this->getUser()) + ->findResources($filter); + } catch (\PDOException $e) { + if ($e->getCode() !== "42000") { + throw $e; + } + + $resources = []; + } foreach ($resources as $resource) { if ($resource->getParent() != null) { From 3ea8d70335ea9f5e51d0e802ecc32042a2e6e08c Mon Sep 17 00:00:00 2001 From: Valentin Hristov Date: Fri, 20 Mar 2020 12:37:04 +0200 Subject: [PATCH 02/17] fix(api): apply the PR feedback sugggestion Resolve MON-5034 --- .../Application/Controller/MonitoringResourceController.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Centreon/Application/Controller/MonitoringResourceController.php b/src/Centreon/Application/Controller/MonitoringResourceController.php index 50a07ffd748..648294a2212 100644 --- a/src/Centreon/Application/Controller/MonitoringResourceController.php +++ b/src/Centreon/Application/Controller/MonitoringResourceController.php @@ -145,10 +145,6 @@ public function list( $resources = $this->resource->filterByContact($this->getUser()) ->findResources($filter); } catch (\PDOException $e) { - if ($e->getCode() !== "42000") { - throw $e; - } - $resources = []; } From 00d6c9b49618f2b9f3fa06d195f80af894ad7ad1 Mon Sep 17 00:00:00 2001 From: Valentin Hristov Date: Fri, 20 Mar 2020 12:53:06 +0200 Subject: [PATCH 03/17] fix(style): add the method filterByContact to the interface ResourceServiceInterface ERROR: Call to an undefined method Centreon\Domain\Monitoring\Interfaces\ResourceServiceInterface::filterByContact() Resolve MON-5034 --- .../Interfaces/ResourceServiceInterface.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Centreon/Domain/Monitoring/Interfaces/ResourceServiceInterface.php b/src/Centreon/Domain/Monitoring/Interfaces/ResourceServiceInterface.php index 0aa9b6a1c57..4206a7019bd 100644 --- a/src/Centreon/Domain/Monitoring/Interfaces/ResourceServiceInterface.php +++ b/src/Centreon/Domain/Monitoring/Interfaces/ResourceServiceInterface.php @@ -104,4 +104,15 @@ interface ResourceServiceInterface * @throws \Exception */ public function findResources(ResourceFilter $filter): array; + + /** + * Used to filter requests according to a contact. + * If the filter is defined, all requests will use the ACL of the contact + * to fetch data. + * + * @param mixed $contact Contact to use as a ACL filter + * @return ResourceServiceInterface + * @throws \Exception + */ + public function filterByContact($contact); } From 544a2ed2209e918520de481fbfd69380e890d157 Mon Sep 17 00:00:00 2001 From: Valentin Hristov Date: Fri, 20 Mar 2020 13:05:13 +0200 Subject: [PATCH 04/17] fix(api): add specific exception for invalid regex Resolve MON-5034 --- .../MonitoringResourceController.php | 9 ++---- .../Exception/ResourceRegExpException.php | 28 +++++++++++++++++++ .../Domain/Monitoring/ResourceService.php | 8 +++++- .../Monitoring/ResourceRepositoryRDB.php | 12 ++++++-- 4 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 src/Centreon/Domain/Monitoring/Exception/ResourceRegExpException.php diff --git a/src/Centreon/Application/Controller/MonitoringResourceController.php b/src/Centreon/Application/Controller/MonitoringResourceController.php index 648294a2212..e8b96b00654 100644 --- a/src/Centreon/Application/Controller/MonitoringResourceController.php +++ b/src/Centreon/Application/Controller/MonitoringResourceController.php @@ -140,13 +140,8 @@ public function list( $context->addExclusionStrategy(new ResourceExclusionStrategy()); - // try to avoid exception from the regexp bad syntax in search criteria - try { - $resources = $this->resource->filterByContact($this->getUser()) - ->findResources($filter); - } catch (\PDOException $e) { - $resources = []; - } + $resources = $this->resource->filterByContact($this->getUser()) + ->findResources($filter); foreach ($resources as $resource) { if ($resource->getParent() != null) { diff --git a/src/Centreon/Domain/Monitoring/Exception/ResourceRegExpException.php b/src/Centreon/Domain/Monitoring/Exception/ResourceRegExpException.php new file mode 100644 index 00000000000..af881a8ed77 --- /dev/null +++ b/src/Centreon/Domain/Monitoring/Exception/ResourceRegExpException.php @@ -0,0 +1,28 @@ +resourceRepository->findResources($filter); + // try to avoid exception from the regexp bad syntax in search criteria + try { + $list = $this->resourceRepository->findResources($filter); + } catch (ResourceRegExpException $exception) { + $list = []; + } // set paths to endpoints foreach ($list as $resource) { diff --git a/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php b/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php index 45c6eafb118..f8b5c350ccc 100644 --- a/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php +++ b/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php @@ -37,7 +37,7 @@ use Centreon\Infrastructure\DatabaseConnection; use Centreon\Infrastructure\RequestParameters\SqlRequestParametersTranslator; use Centreon\Infrastructure\CentreonLegacyDB\StatementCollector; -use CentreonDuration; +use Centreon\Domain\Monitoring\Exception\ResourceRegExpException; use PDO; /** @@ -229,7 +229,15 @@ public function findResources(ResourceFilter $filter): array $statement = $this->db->prepare($request); $collector->bind($statement); - $statement->execute(); + try { + $statement->execute(); + } catch (\PDOException $exception) { + if ($exception->getCode() !== "42000") { + throw $exception; + } + + throw new ResourceRegExpException($exception->getMessage(), (int)$exception->getCode(), $exception); + } $this->sqlRequestTranslator->getRequestParameters()->setTotal( (int)$this->db->query('SELECT FOUND_ROWS()')->fetchColumn() From 01169ebdfacbd1921c64b2a2e1858c8e71a55023 Mon Sep 17 00:00:00 2001 From: Valentin Hristov Date: Fri, 20 Mar 2020 13:09:37 +0200 Subject: [PATCH 05/17] fix(api): add missing method in the interface ResourceRepositoryInterface Resolve MON-5034 --- .../Monitoring/Interfaces/ResourceRepositoryInterface.php | 8 ++++++++ .../Infrastructure/Monitoring/ResourceRepositoryRDB.php | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Centreon/Domain/Monitoring/Interfaces/ResourceRepositoryInterface.php b/src/Centreon/Domain/Monitoring/Interfaces/ResourceRepositoryInterface.php index 0994233c303..3ef77a0c122 100644 --- a/src/Centreon/Domain/Monitoring/Interfaces/ResourceRepositoryInterface.php +++ b/src/Centreon/Domain/Monitoring/Interfaces/ResourceRepositoryInterface.php @@ -40,4 +40,12 @@ public function findResources(ResourceFilter $filter): array; * @return ResourceRepositoryInterface */ public function setContact(ContactInterface $contact): self; + + /** + * Sets the access groups that will be used to filter services and the host. + * + * @param AccessGroup[]|null $accessGroups + * @return ResourceRepositoryInterface + */ + public function filterByAccessGroups(?array $accessGroups): ResourceRepositoryInterface; } diff --git a/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php b/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php index f8b5c350ccc..e12f87c3e5a 100644 --- a/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php +++ b/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php @@ -131,9 +131,9 @@ public function setSqlRequestTranslator(SqlRequestParametersTranslator $sqlReque } /** - * @inheritDoc + * {@inheritDoc} */ - public function filterByAccessGroups(?array $accessGroups): self + public function filterByAccessGroups(?array $accessGroups): ResourceRepositoryInterface { $this->accessGroups = $accessGroups; From c0a1dd09d8bd13caececbd0eb04808a2a61609f3 Mon Sep 17 00:00:00 2001 From: Valentin Hristov Date: Fri, 20 Mar 2020 13:32:27 +0200 Subject: [PATCH 06/17] fix(style): improve code style Resolve MON-5034 --- .../Domain/Monitoring/Exception/ResourceRegExpException.php | 1 - .../Monitoring/Interfaces/ResourceRepositoryInterface.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Centreon/Domain/Monitoring/Exception/ResourceRegExpException.php b/src/Centreon/Domain/Monitoring/Exception/ResourceRegExpException.php index af881a8ed77..aa2aaef945b 100644 --- a/src/Centreon/Domain/Monitoring/Exception/ResourceRegExpException.php +++ b/src/Centreon/Domain/Monitoring/Exception/ResourceRegExpException.php @@ -24,5 +24,4 @@ class ResourceRegExpException extends \PDOException { - } diff --git a/src/Centreon/Domain/Monitoring/Interfaces/ResourceRepositoryInterface.php b/src/Centreon/Domain/Monitoring/Interfaces/ResourceRepositoryInterface.php index 3ef77a0c122..e086b294824 100644 --- a/src/Centreon/Domain/Monitoring/Interfaces/ResourceRepositoryInterface.php +++ b/src/Centreon/Domain/Monitoring/Interfaces/ResourceRepositoryInterface.php @@ -44,7 +44,7 @@ public function setContact(ContactInterface $contact): self; /** * Sets the access groups that will be used to filter services and the host. * - * @param AccessGroup[]|null $accessGroups + * @param \Centreon\Domain\Security\AccessGroup\AccessGroup[]|null $accessGroups * @return ResourceRepositoryInterface */ public function filterByAccessGroups(?array $accessGroups): ResourceRepositoryInterface; From dc2e41f2b88380ed58a429a86cc9897592f3fb60 Mon Sep 17 00:00:00 2001 From: Valentin Hristov Date: Fri, 20 Mar 2020 13:34:16 +0200 Subject: [PATCH 07/17] fix(style): improve reported code style issues Resolve MON-5034 --- .../Infrastructure/Monitoring/ResourceRepositoryRDB.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php b/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php index e12f87c3e5a..a59b593d2f5 100644 --- a/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php +++ b/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php @@ -48,7 +48,7 @@ final class ResourceRepositoryRDB extends AbstractRepositoryDRB implements ResourceRepositoryInterface { /** - * @var AccessGroup[] List of access group used to filter the requests + * @var AccessGroup[]|null List of access group used to filter the requests */ private $accessGroups = []; From 0607f0be929725a6cb4e70b757d0edde4e2a3a66 Mon Sep 17 00:00:00 2001 From: Valentin Hristov Date: Fri, 20 Mar 2020 13:56:07 +0200 Subject: [PATCH 08/17] fix(style): fix typo in namespace Resolve MON-5034 --- .../Monitoring/Interfaces/ResourceRepositoryInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Centreon/Domain/Monitoring/Interfaces/ResourceRepositoryInterface.php b/src/Centreon/Domain/Monitoring/Interfaces/ResourceRepositoryInterface.php index e086b294824..9acfea80735 100644 --- a/src/Centreon/Domain/Monitoring/Interfaces/ResourceRepositoryInterface.php +++ b/src/Centreon/Domain/Monitoring/Interfaces/ResourceRepositoryInterface.php @@ -44,7 +44,7 @@ public function setContact(ContactInterface $contact): self; /** * Sets the access groups that will be used to filter services and the host. * - * @param \Centreon\Domain\Security\AccessGroup\AccessGroup[]|null $accessGroups + * @param \Centreon\Domain\Security\AccessGroup[]|null $accessGroups * @return ResourceRepositoryInterface */ public function filterByAccessGroups(?array $accessGroups): ResourceRepositoryInterface; From 7134e6fd8c4c87e074dde96a4df620ec3f25bd51 Mon Sep 17 00:00:00 2001 From: Laurent Calvet Date: Mon, 23 Mar 2020 00:35:41 +0100 Subject: [PATCH 09/17] Checking the regex in the search request --- .../RequestParameters/SqlRequestParametersTranslator.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Centreon/Infrastructure/RequestParameters/SqlRequestParametersTranslator.php b/src/Centreon/Infrastructure/RequestParameters/SqlRequestParametersTranslator.php index 07030edb32a..e4a6353e043 100644 --- a/src/Centreon/Infrastructure/RequestParameters/SqlRequestParametersTranslator.php +++ b/src/Centreon/Infrastructure/RequestParameters/SqlRequestParametersTranslator.php @@ -255,6 +255,14 @@ private function createQueryOnKeyValue(string $key, $valueOrArray): string || $searchOperator === RequestParameters::OPERATOR_NOT_LIKE || $searchOperator === RequestParameters::OPERATOR_REGEXP ) { + // We check the regex + if ($searchOperator === RequestParameters::OPERATOR_REGEXP) { + try { + preg_match($mixedValue, ''); + } catch (\Throwable $ex) { + throw new RequestParametersTranslatorException('Bad regex format \'' . $mixedValue . '\'', 0, $ex); + } + } $type = \PDO::PARAM_STR; $bindKey = ':value_' . (count($this->searchValues) + 1); $this->searchValues[$bindKey] = [$type => $mixedValue]; From 6fb8469ab911fd152a145eb0d28e2437784b7b7c Mon Sep 17 00:00:00 2001 From: Laurent Calvet Date: Mon, 23 Mar 2020 01:21:55 +0100 Subject: [PATCH 10/17] Replace the regex exception --- ...sourceRegExpException.php => ResourceException.php} | 2 +- src/Centreon/Domain/Monitoring/ResourceService.php | 5 +++-- .../Monitoring/ResourceRepositoryRDB.php | 10 +--------- 3 files changed, 5 insertions(+), 12 deletions(-) rename src/Centreon/Domain/Monitoring/Exception/{ResourceRegExpException.php => ResourceException.php} (93%) diff --git a/src/Centreon/Domain/Monitoring/Exception/ResourceRegExpException.php b/src/Centreon/Domain/Monitoring/Exception/ResourceException.php similarity index 93% rename from src/Centreon/Domain/Monitoring/Exception/ResourceRegExpException.php rename to src/Centreon/Domain/Monitoring/Exception/ResourceException.php index aa2aaef945b..865487d6d43 100644 --- a/src/Centreon/Domain/Monitoring/Exception/ResourceRegExpException.php +++ b/src/Centreon/Domain/Monitoring/Exception/ResourceException.php @@ -22,6 +22,6 @@ namespace Centreon\Domain\Monitoring\Exception; -class ResourceRegExpException extends \PDOException +class ResourceException extends \Exception { } diff --git a/src/Centreon/Domain/Monitoring/ResourceService.php b/src/Centreon/Domain/Monitoring/ResourceService.php index 7d9a753217f..5d7aa63cd82 100644 --- a/src/Centreon/Domain/Monitoring/ResourceService.php +++ b/src/Centreon/Domain/Monitoring/ResourceService.php @@ -22,6 +22,7 @@ namespace Centreon\Domain\Monitoring; +use Centreon\Domain\Monitoring\Exception\ResourceException; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Centreon\Domain\Monitoring\Interfaces\ResourceServiceInterface; use Centreon\Domain\Monitoring\Interfaces\ResourceRepositoryInterface; @@ -91,8 +92,8 @@ public function findResources(ResourceFilter $filter): array // try to avoid exception from the regexp bad syntax in search criteria try { $list = $this->resourceRepository->findResources($filter); - } catch (ResourceRegExpException $exception) { - $list = []; + } catch (ResourceException $ex) { + throw new ResourceException('Error while searching for resources', 0, $ex); } // set paths to endpoints diff --git a/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php b/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php index a59b593d2f5..14619539039 100644 --- a/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php +++ b/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php @@ -229,15 +229,7 @@ public function findResources(ResourceFilter $filter): array $statement = $this->db->prepare($request); $collector->bind($statement); - try { - $statement->execute(); - } catch (\PDOException $exception) { - if ($exception->getCode() !== "42000") { - throw $exception; - } - - throw new ResourceRegExpException($exception->getMessage(), (int)$exception->getCode(), $exception); - } + $statement->execute(); $this->sqlRequestTranslator->getRequestParameters()->setTotal( (int)$this->db->query('SELECT FOUND_ROWS()')->fetchColumn() From 3d9912c678a2676ee803ae4da01309b3e5fd85a8 Mon Sep 17 00:00:00 2001 From: Laurent Calvet Date: Mon, 23 Mar 2020 11:18:57 +0100 Subject: [PATCH 11/17] Surrounds the pattern with the regex delimiter --- .../RequestParameters/SqlRequestParametersTranslator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Centreon/Infrastructure/RequestParameters/SqlRequestParametersTranslator.php b/src/Centreon/Infrastructure/RequestParameters/SqlRequestParametersTranslator.php index e4a6353e043..4347b952080 100644 --- a/src/Centreon/Infrastructure/RequestParameters/SqlRequestParametersTranslator.php +++ b/src/Centreon/Infrastructure/RequestParameters/SqlRequestParametersTranslator.php @@ -258,7 +258,7 @@ private function createQueryOnKeyValue(string $key, $valueOrArray): string // We check the regex if ($searchOperator === RequestParameters::OPERATOR_REGEXP) { try { - preg_match($mixedValue, ''); + preg_match('/' . $mixedValue . '/', ''); } catch (\Throwable $ex) { throw new RequestParametersTranslatorException('Bad regex format \'' . $mixedValue . '\'', 0, $ex); } From ed76054dc46c2fb49030c38e3597e9b8b0c2ece2 Mon Sep 17 00:00:00 2001 From: Valentin Hristov Date: Mon, 23 Mar 2020 13:28:58 +0200 Subject: [PATCH 12/17] fix(style): revert code style improvment Resolve MON-5034 --- .../Infrastructure/Monitoring/ResourceRepositoryRDB.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php b/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php index 14619539039..f1307599b7d 100644 --- a/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php +++ b/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php @@ -48,7 +48,7 @@ final class ResourceRepositoryRDB extends AbstractRepositoryDRB implements ResourceRepositoryInterface { /** - * @var AccessGroup[]|null List of access group used to filter the requests + * @var AccessGroup[] List of access group used to filter the requests */ private $accessGroups = []; From dcca810f6b78cdd2d8f5b8c932cd1f3b235931e5 Mon Sep 17 00:00:00 2001 From: Laurent Calvet Date: Mon, 23 Mar 2020 13:49:41 +0100 Subject: [PATCH 13/17] Modification of the exception catch --- src/Centreon/Domain/Monitoring/ResourceService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Centreon/Domain/Monitoring/ResourceService.php b/src/Centreon/Domain/Monitoring/ResourceService.php index 5d7aa63cd82..27c2721430c 100644 --- a/src/Centreon/Domain/Monitoring/ResourceService.php +++ b/src/Centreon/Domain/Monitoring/ResourceService.php @@ -92,7 +92,7 @@ public function findResources(ResourceFilter $filter): array // try to avoid exception from the regexp bad syntax in search criteria try { $list = $this->resourceRepository->findResources($filter); - } catch (ResourceException $ex) { + } catch (\Exception $ex) { throw new ResourceException('Error while searching for resources', 0, $ex); } From 6b3fec9ad36890df48be16fb99e5132644df72cd Mon Sep 17 00:00:00 2001 From: Laurent Calvet Date: Mon, 23 Mar 2020 15:29:20 +0100 Subject: [PATCH 14/17] Delete useless imports into the resource repository --- src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php b/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php index f1307599b7d..4a1e492874e 100644 --- a/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php +++ b/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php @@ -37,7 +37,6 @@ use Centreon\Infrastructure\DatabaseConnection; use Centreon\Infrastructure\RequestParameters\SqlRequestParametersTranslator; use Centreon\Infrastructure\CentreonLegacyDB\StatementCollector; -use Centreon\Domain\Monitoring\Exception\ResourceRegExpException; use PDO; /** From f0864e735f4fd49024bb39e84888c6f712ea490e Mon Sep 17 00:00:00 2001 From: Valentin Hristov Date: Tue, 24 Mar 2020 11:04:38 +0200 Subject: [PATCH 15/17] Update src/Centreon/Domain/Monitoring/ResourceService.php Co-Authored-By: Laurent Calvet --- src/Centreon/Domain/Monitoring/ResourceService.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Centreon/Domain/Monitoring/ResourceService.php b/src/Centreon/Domain/Monitoring/ResourceService.php index 27c2721430c..025cafecc7c 100644 --- a/src/Centreon/Domain/Monitoring/ResourceService.php +++ b/src/Centreon/Domain/Monitoring/ResourceService.php @@ -29,7 +29,6 @@ use Centreon\Domain\Security\Interfaces\AccessGroupRepositoryInterface; use Centreon\Domain\Service\AbstractCentreonService; use Centreon\Domain\Monitoring\ResourceFilter; -use Centreon\Domain\Monitoring\Exception\ResourceRegExpException; /** * Service manage the resources in real-time monitoring : hosts and services. From d5045d9e01ded0c8744e618df5b37570a7f2ae74 Mon Sep 17 00:00:00 2001 From: Laurent Calvet Date: Tue, 24 Mar 2020 11:35:43 +0100 Subject: [PATCH 16/17] Raises an exception if the regex is badly formed in a production context --- .../RequestParameters/SqlRequestParametersTranslator.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Centreon/Infrastructure/RequestParameters/SqlRequestParametersTranslator.php b/src/Centreon/Infrastructure/RequestParameters/SqlRequestParametersTranslator.php index 4347b952080..9b75dc7e2de 100644 --- a/src/Centreon/Infrastructure/RequestParameters/SqlRequestParametersTranslator.php +++ b/src/Centreon/Infrastructure/RequestParameters/SqlRequestParametersTranslator.php @@ -260,6 +260,10 @@ private function createQueryOnKeyValue(string $key, $valueOrArray): string try { preg_match('/' . $mixedValue . '/', ''); } catch (\Throwable $ex) { + // No exception in prod environment + throw new RequestParametersTranslatorException('Bad regex format \'' . $mixedValue . '\'', 0, $ex); + } + if (preg_last_error() !== PREG_NO_ERROR) { throw new RequestParametersTranslatorException('Bad regex format \'' . $mixedValue . '\'', 0, $ex); } } From cf1770ab157f60ac1d1f8dfd990271b1be7288e2 Mon Sep 17 00:00:00 2001 From: Laurent Calvet Date: Tue, 24 Mar 2020 11:56:35 +0100 Subject: [PATCH 17/17] Update src/Centreon/Infrastructure/RequestParameters/SqlRequestParametersTranslator.php --- .../RequestParameters/SqlRequestParametersTranslator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Centreon/Infrastructure/RequestParameters/SqlRequestParametersTranslator.php b/src/Centreon/Infrastructure/RequestParameters/SqlRequestParametersTranslator.php index 9b75dc7e2de..009fa9c06ab 100644 --- a/src/Centreon/Infrastructure/RequestParameters/SqlRequestParametersTranslator.php +++ b/src/Centreon/Infrastructure/RequestParameters/SqlRequestParametersTranslator.php @@ -264,7 +264,7 @@ private function createQueryOnKeyValue(string $key, $valueOrArray): string throw new RequestParametersTranslatorException('Bad regex format \'' . $mixedValue . '\'', 0, $ex); } if (preg_last_error() !== PREG_NO_ERROR) { - throw new RequestParametersTranslatorException('Bad regex format \'' . $mixedValue . '\'', 0, $ex); + throw new RequestParametersTranslatorException('Bad regex format \'' . $mixedValue . '\'', 0); } } $type = \PDO::PARAM_STR;