Skip to content

Commit

Permalink
use preg replace callback to prevent values containing a '?' from hav…
Browse files Browse the repository at this point in the history
…ing other values injected inside it.
  • Loading branch information
b-hayes committed May 17, 2023
1 parent 12f625c commit 0e9fc19
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/PicoDb/StatementHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,12 @@ protected function beforeExecute()
if ($this->logQueries) {
$sql = $this->sql;
if ($this->logQueryValues) {
foreach ($this->lobParams as $value) {
$sql = substr_replace($sql, "'$value'", strpos($sql, '?'), 1);
}
$i = 0;
$values = $this->lobParams;
return preg_replace_callback('/\?/', function() use ($values, &$i) {
$i++;
return $values[$i] ?? '';
}, $sql);
}
$this->db->setLogMessage($sql);
}
Expand Down

0 comments on commit 0e9fc19

Please sign in to comment.