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