Db: Fix checksum escaping :)

This commit is contained in:
Alexander Fuhr 2015-06-23 16:45:25 +02:00
parent a412a9fec2
commit da7cc607e5
3 changed files with 19 additions and 5 deletions

View File

@ -25,14 +25,23 @@ class Db extends DbConnection
}
public function fetchActivityLogEntry($checksum)
{
{
if ($this->getDbType() === 'pgsql') {
$checksum = Util::pgBinEscape($checksum);
$checksum = new \Zend_Db_Expr("\\x" . bin2hex($checksum));
}
$sql = 'SELECT * FROM director_activity_log WHERE checksum = ?';
$ret = $this->db()->fetchRow($sql, $checksum);
return $this->db()->fetchRow($sql, $checksum);
if (is_resource($ret->checksum)) {
$ret->checksum = stream_get_contents($ret->checksum);
}
if (is_resource($ret->parent_checksum)) {
$ret->checksum = stream_get_contents($ret->parent_checksum);
}
return $ret;
}
public function getLastActivityChecksum()

View File

@ -133,9 +133,14 @@ class IcingaConfig
try {
$existingQuery = $this->db->select()
->from($fileTable, 'checksum')
->where('checksum IN (?)', array_map(array($this, 'dbBin'), $this->getFilesChecksums()));
->where('checksum IN (?)', array_map(array($this, 'dbBin'), $this->getFilesChecksums()));
$existing = $this->db->fetchCol($existingQuery);
foreach ($existing as $key => $val) {
if (is_resource($val)) {
$existing[$key] = stream_get_contents($val);
}
}
$missing = array_diff($this->getFilesChecksums(), $existing);

View File

@ -8,7 +8,7 @@ class Util
{
public static function pgBinEscape($binary)
{
return new Zend_Db_Expr("'" . pg_escape_bytea($binary) . "'");
return new \Zend_Db_Expr("'\\x" . bin2hex($binary) . "'");
}
public static function hex2binary($bin)