From fbe899e85fdbf0b71a83fe30c3c37d2f983a4648 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Fri, 7 Jan 2022 10:40:31 +0000 Subject: [PATCH 1/2] Close curl handles after use --- composer.json | 1 + src/Utils/WebDAV.php | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index f6088ad..72e2246 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,7 @@ ], "require": { "php": ">=7.1", + "ext-curl": "*", "silverstripe/framework": "^4.0", "monolog/monolog": "~1.15", "ptcinc/solr-php-client": "^1.0", diff --git a/src/Utils/WebDAV.php b/src/Utils/WebDAV.php index a3a51ad..1243261 100644 --- a/src/Utils/WebDAV.php +++ b/src/Utils/WebDAV.php @@ -22,10 +22,14 @@ class WebDAV } $ch = self::curl_init($url, 'PROPFIND'); - - $res = curl_exec($ch); + + curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $err = curl_error($ch); + + curl_close($ch); + if ($code == 404) { return false; } @@ -33,8 +37,6 @@ class WebDAV return true; } - $err = curl_error($ch); - user_error("Got error from webdav server - " . $err, E_USER_ERROR); } @@ -42,8 +44,9 @@ class WebDAV { $ch = self::curl_init(rtrim($url, '/') . '/', 'MKCOL'); - $res = curl_exec($ch); + curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); return $code == 201; } @@ -58,10 +61,12 @@ class WebDAV curl_setopt($ch, CURLOPT_INFILE, $handle); - $res = curl_exec($ch); + curl_exec($ch); fclose($handle); + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); - return curl_getinfo($ch, CURLINFO_HTTP_CODE); + return $code; } public static function upload_from_string($string, $url) From 2c0e2df02d3c970606e384b3fdccec42e06fd1f9 Mon Sep 17 00:00:00 2001 From: GuySartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Thu, 27 Jan 2022 11:23:19 +1300 Subject: [PATCH 2/2] FIX Don't assume DataObject::canView always returns bool (#306) Because there is no return value typehinting in DataObject::canView, the value returned from that method can be of any type. We must cast to boolean before returning the value to avoid possible errors with non-boolean return types. --- src/Search/Services/SearchableService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Search/Services/SearchableService.php b/src/Search/Services/SearchableService.php index a621a75..421d06f 100644 --- a/src/Search/Services/SearchableService.php +++ b/src/Search/Services/SearchableService.php @@ -151,12 +151,12 @@ class SearchableService // Anonymous member canView() for indexing if (!$this->classSkipsCanViewCheck($objClass)) { $value = Member::actAs(null, function () use ($obj) { - return $obj->canView(); + return (bool) $obj->canView(); }); } } else { // Current member canView() check for retrieving search results - $value = $obj->canView(); + $value = (bool) $obj->canView(); } } $this->extend('updateIsSearchable', $obj, $indexing, $value);