From 61c8f9ad257749254d5ee85625870b641c59beba Mon Sep 17 00:00:00 2001 From: Kamil Wylegala Date: Sat, 21 Sep 2024 12:53:44 +0200 Subject: [PATCH] Added PDOException wrapper to avoid creating dynamic property. (#77) --- README.md | 4 ++++ lib/Cake/Model/Datasource/DboSource.php | 8 +++++--- .../Datasource/PDOExceptionWithQueryString.php | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 lib/Cake/Model/Datasource/PDOExceptionWithQueryString.php diff --git a/README.md b/README.md index fb2149147..773536179 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,10 @@ It means that composer will look at `master` branch of repository configured und ## Changelog +### 2024-09-21 + +- Added wrapper for PDOException to avoid creating dynamic property `queryString`. + ### 2024-07-24 - Csrf vulnerabity fix back ported from Cake PHP 3 diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index da3ffb911..d356492df 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -17,6 +17,7 @@ */ App::uses('DataSource', 'Model/Datasource'); +App::uses('PDOExceptionWithQueryString', 'Model/Datasource'); App::uses('CakeText', 'Utility'); App::uses('View', 'View'); @@ -512,12 +513,13 @@ class DboSource extends DataSource { } return $query; } catch (PDOException $e) { + $wrapperException = new PDOExceptionWithQueryString($e); if (isset($query->queryString)) { - $e->queryString = $query->queryString; + $wrapperException->queryString = $query->queryString; } else { - $e->queryString = $sql; + $wrapperException->queryString = $sql; } - throw $e; + throw $wrapperException; } } diff --git a/lib/Cake/Model/Datasource/PDOExceptionWithQueryString.php b/lib/Cake/Model/Datasource/PDOExceptionWithQueryString.php new file mode 100644 index 000000000..dd59c9e06 --- /dev/null +++ b/lib/Cake/Model/Datasource/PDOExceptionWithQueryString.php @@ -0,0 +1,17 @@ +getMessage(), 0, $e->getPrevious()); + + $this->code = $e->code; + } +}