Fix infinite loop using postgres as backend

unescapebin is handed a string in some cases, and it causes an infinite
loop when it does.  This ensures that the argument is a resource before
loading its contents.
This commit is contained in:
Daniel Lowe 2019-04-21 11:14:17 +00:00
parent a6a17a85f3
commit 9a6531e2a2

View File

@ -161,23 +161,17 @@ class dba_pdo extends dba_driver {
}
function unescapebin($str) {
if($this->driver_dbtype === 'pgsql' && (! is_null($str))) {
$x = '';
while(! feof($str)) {
$x .= fread($str,8192);
if($this->driver_dbtype === 'pgsql') {
if(gettype($str) === 'resource') {
$str = stream_get_contents($str);
}
if(substr($x,0,2) === '\\x') {
$x = hex2bin(substr($x,2));
if(substr($str,0,2) === '\\x') {
$str = hex2bin(substr($str,2));
}
return $x;
}
else {
return $str;
}
return $str;
}
function getdriver() {
return 'pdo';
}