Compare commits

..

2 commits

Author SHA1 Message Date
Kamil Wylegala
cb3382f6d2
Fixed errorInfo in pdo exception wrapper. (#78)
Some checks failed
PHP Coding Standard / phpcs (7.4) (push) Has been cancelled
Tests / linux-tests (mysql, 8.0) (push) Has been cancelled
Tests / linux-tests (mysql, 8.1) (push) Has been cancelled
Tests / linux-tests (pgsql, 8.0) (push) Has been cancelled
Tests / linux-tests (sqlite, 8.0) (push) Has been cancelled
2024-09-21 13:04:20 +02:00
Kamil Wylegala
61c8f9ad25
Added PDOException wrapper to avoid creating dynamic property. (#77) 2024-09-21 12:53:44 +02:00
3 changed files with 27 additions and 3 deletions

View file

@ -59,6 +59,10 @@ It means that composer will look at `master` branch of repository configured und
## Changelog ## Changelog
### 2024-09-21
- Added wrapper for PDOException to avoid creating dynamic property `queryString`.
### 2024-07-24 ### 2024-07-24
- Csrf vulnerabity fix back ported from Cake PHP 3 - Csrf vulnerabity fix back ported from Cake PHP 3

View file

@ -17,6 +17,7 @@
*/ */
App::uses('DataSource', 'Model/Datasource'); App::uses('DataSource', 'Model/Datasource');
App::uses('PDOExceptionWithQueryString', 'Model/Datasource');
App::uses('CakeText', 'Utility'); App::uses('CakeText', 'Utility');
App::uses('View', 'View'); App::uses('View', 'View');
@ -512,12 +513,13 @@ class DboSource extends DataSource {
} }
return $query; return $query;
} catch (PDOException $e) { } catch (PDOException $e) {
$wrapperException = new PDOExceptionWithQueryString($e);
if (isset($query->queryString)) { if (isset($query->queryString)) {
$e->queryString = $query->queryString; $wrapperException->queryString = $query->queryString;
} else { } else {
$e->queryString = $sql; $wrapperException->queryString = $sql;
} }
throw $e; throw $wrapperException;
} }
} }

View file

@ -0,0 +1,18 @@
<?php
class PDOExceptionWithQueryString extends PDOException {
public string $queryString = "";
/**
* Wrapper for PDOException to avoid creating dynamic property.
*
* @param PDOException $e Source exception.
*/
public function __construct(PDOException $e) {
parent::__construct($e->getMessage(), 0, $e->getPrevious());
$this->errorInfo = $e->errorInfo;
$this->code = $e->code;
}
}