diff --git a/lib/Controller.php b/lib/Controller.php index e94751e8..0b69ccec 100644 --- a/lib/Controller.php +++ b/lib/Controller.php @@ -319,7 +319,8 @@ class Controller $paste->setData($data); $paste->store(); } catch (Exception $e) { - return $this->_return_message(1, $e->getMessage()); + $this->_return_message(1, $e->getMessage()); + return; } $this->_return_message(0, $paste->getId(), array('deletetoken' => $paste->getDeleteToken())); } diff --git a/lib/Data/Database.php b/lib/Data/Database.php index d7f40c0c..0fd42dcc 100644 --- a/lib/Data/Database.php +++ b/lib/Data/Database.php @@ -296,7 +296,7 @@ class Database extends AbstractData // create comment list $comments = array(); - if (is_array($rows) && count($rows)) { + if (count($rows)) { foreach ($rows as $row) { $i = $this->getOpenSlot($comments, (int) $row['postdate']); $comments[$i] = Json::decode($row['data']); @@ -386,7 +386,7 @@ class Database extends AbstractData $fs = new Filesystem(array('dir' => 'data')); $value = $fs->getValue('salt'); $this->setValue($value, 'salt'); - @unlink($file); + unlink($file); return $value; } } @@ -467,7 +467,7 @@ class Database extends AbstractData * @param array $params * @param bool $firstOnly if only the first row should be returned * @throws PDOException - * @return array|false + * @return array */ private function _select($sql, array $params, $firstOnly = false) { @@ -475,6 +475,10 @@ class Database extends AbstractData $statement->execute($params); if ($firstOnly) { $result = $statement->fetch(PDO::FETCH_ASSOC); + if ($this->_type === 'oci' && is_array($result)) { + // returned CLOB values are streams, convert these into strings + $result = array_map('PrivateBin\Data\Database::_sanitizeClob', $result); + } } elseif ($this->_type === 'oci') { // workaround for https://bugs.php.net/bug.php?id=46728 $result = array(); @@ -485,12 +489,6 @@ class Database extends AbstractData $result = $statement->fetchAll(PDO::FETCH_ASSOC); } $statement->closeCursor(); - if ($this->_type === 'oci' && is_array($result)) { - // returned CLOB values are streams, convert these into strings - $result = $firstOnly ? - array_map('PrivateBin\Data\Database::_sanitizeClob', $result) : - $result; - } return $result; } @@ -763,7 +761,7 @@ class Database extends AbstractData if ($this->_type === 'sqlite') { try { $row = $this->_select('SELECT sqlite_version() AS "v"', array(), true); - $supportsDropColumn = version_compare($row['v'], '3.35.0', '>='); + $supportsDropColumn = (bool) version_compare($row['v'], '3.35.0', '>='); } catch (PDOException $e) { $supportsDropColumn = false; } diff --git a/lib/Data/Filesystem.php b/lib/Data/Filesystem.php index a74855e2..0e5f9edd 100644 --- a/lib/Data/Filesystem.php +++ b/lib/Data/Filesystem.php @@ -69,10 +69,7 @@ class Filesystem extends AbstractData public function __construct(array $options) { // if given update the data directory - if ( - is_array($options) && - array_key_exists('dir', $options) - ) { + if (array_key_exists('dir', $options)) { $this->_path = $options['dir']; } } @@ -315,7 +312,7 @@ class Filesystem extends AbstractData $file = $this->_path . DIRECTORY_SEPARATOR . 'salt.php'; if (is_readable($file)) { $items = explode('|', file_get_contents($file)); - if (is_array($items) && count($items) == 3) { + if (count($items) == 3) { return $items[1]; } } @@ -505,7 +502,7 @@ class Filesystem extends AbstractData if ($fileCreated === false || $writtenBytes === false || $writtenBytes < strlen($data)) { return false; } - @chmod($filename, 0640); // protect file from access by other users on the host + chmod($filename, 0640); // protect file from access by other users on the host return true; } diff --git a/lib/Data/GoogleCloudStorage.php b/lib/Data/GoogleCloudStorage.php index 2ab5d296..9f64abe5 100644 --- a/lib/Data/GoogleCloudStorage.php +++ b/lib/Data/GoogleCloudStorage.php @@ -62,13 +62,13 @@ class GoogleCloudStorage extends AbstractData if (getenv('PRIVATEBIN_GCS_BUCKET')) { $bucket = getenv('PRIVATEBIN_GCS_BUCKET'); } - if (is_array($options) && array_key_exists('bucket', $options)) { + if (array_key_exists('bucket', $options)) { $bucket = $options['bucket']; } - if (is_array($options) && array_key_exists('prefix', $options)) { + if (array_key_exists('prefix', $options)) { $this->_prefix = $options['prefix']; } - if (is_array($options) && array_key_exists('uniformacl', $options)) { + if (array_key_exists('uniformacl', $options)) { $this->_uniformacl = $options['uniformacl']; } diff --git a/lib/Data/S3Storage.php b/lib/Data/S3Storage.php index e72285f2..526a9ec2 100644 --- a/lib/Data/S3Storage.php +++ b/lib/Data/S3Storage.php @@ -81,33 +81,31 @@ class S3Storage extends AbstractData */ public function __construct(array $options) { - if (is_array($options)) { - // AWS SDK will try to load credentials from environment if credentials are not passed via configuration - // ref: https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html#default-credential-chain - if (isset($options['accesskey']) && isset($options['secretkey'])) { - $this->_options['credentials'] = array(); + // AWS SDK will try to load credentials from environment if credentials are not passed via configuration + // ref: https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html#default-credential-chain + if (isset($options['accesskey']) && isset($options['secretkey'])) { + $this->_options['credentials'] = array(); - $this->_options['credentials']['key'] = $options['accesskey']; - $this->_options['credentials']['secret'] = $options['secretkey']; - } - if (array_key_exists('region', $options)) { - $this->_options['region'] = $options['region']; - } - if (array_key_exists('version', $options)) { - $this->_options['version'] = $options['version']; - } - if (array_key_exists('endpoint', $options)) { - $this->_options['endpoint'] = $options['endpoint']; - } - if (array_key_exists('use_path_style_endpoint', $options)) { - $this->_options['use_path_style_endpoint'] = filter_var($options['use_path_style_endpoint'], FILTER_VALIDATE_BOOLEAN); - } - if (array_key_exists('bucket', $options)) { - $this->_bucket = $options['bucket']; - } - if (array_key_exists('prefix', $options)) { - $this->_prefix = $options['prefix']; - } + $this->_options['credentials']['key'] = $options['accesskey']; + $this->_options['credentials']['secret'] = $options['secretkey']; + } + if (array_key_exists('region', $options)) { + $this->_options['region'] = $options['region']; + } + if (array_key_exists('version', $options)) { + $this->_options['version'] = $options['version']; + } + if (array_key_exists('endpoint', $options)) { + $this->_options['endpoint'] = $options['endpoint']; + } + if (array_key_exists('use_path_style_endpoint', $options)) { + $this->_options['use_path_style_endpoint'] = filter_var($options['use_path_style_endpoint'], FILTER_VALIDATE_BOOLEAN); + } + if (array_key_exists('bucket', $options)) { + $this->_bucket = $options['bucket']; + } + if (array_key_exists('prefix', $options)) { + $this->_prefix = $options['prefix']; } $this->_client = new S3Client($this->_options); @@ -285,7 +283,8 @@ class S3Storage extends AbstractData 'Bucket' => $this->_bucket, 'Key' => $entry['Key'], )); - $body = JSON::decode($object['Body']->getContents()); + $data = $object['Body']->getContents(); + $body = JSON::decode($data); $items = explode('/', $entry['Key']); $body['id'] = $items[3]; $body['parentid'] = $items[2]; diff --git a/lib/Vizhash16x16.php b/lib/Vizhash16x16.php index 729f1f0d..74fcfc57 100644 --- a/lib/Vizhash16x16.php +++ b/lib/Vizhash16x16.php @@ -93,6 +93,9 @@ class Vizhash16x16 // Then use these integers to drive the creation of an image. $image = imagecreatetruecolor($this->width, $this->height); + if ($image === false) { + return ''; + } $r = $r0 = $this->getInt(); $g = $g0 = $this->getInt();