Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added PDOException wrapper to avoid creating dynamic property. #77

Merged
merged 1 commit into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading