Skip to content

Commit

Permalink
Added PDOException wrapper to avoid creating dynamic property.
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilwylegala committed Sep 21, 2024
1 parent 7e1da9a commit 6b52092
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions lib/Cake/Model/Datasource/DboSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

App::uses('DataSource', 'Model/Datasource');
App::uses('PDOExceptionWithQueryString', 'Model/Datasource');
App::uses('CakeText', 'Utility');
App::uses('View', 'View');

Expand Down Expand Up @@ -512,12 +513,13 @@ protected function _execute($sql, $params = array(), $prepareOptions = array())
}
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;
}
}

Expand Down
17 changes: 17 additions & 0 deletions lib/Cake/Model/Datasource/PDOExceptionWithQueryString.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?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->code = $e->code;
}
}

0 comments on commit 6b52092

Please sign in to comment.