Merge pull request #8721 from annando/fatal

Fix fatal errors because of mixed data types
This commit is contained in:
Hypolite Petovan 2020-06-03 04:09:49 -04:00 committed by GitHub
commit ce0f67f10f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 39 additions and 39 deletions

View File

@ -172,7 +172,7 @@ class Probe
} elseif ($curlResult->isTimeout()) { } elseif ($curlResult->isTimeout()) {
Logger::info('Probing timeout', ['url' => $ssl_url], Logger::DEBUG); Logger::info('Probing timeout', ['url' => $ssl_url], Logger::DEBUG);
self::$istimeout = true; self::$istimeout = true;
return false; return [];
} }
if (!is_object($xrd) && !empty($url)) { if (!is_object($xrd) && !empty($url)) {
@ -181,10 +181,10 @@ class Probe
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
Logger::info('Probing timeout', ['url' => $url], Logger::DEBUG); Logger::info('Probing timeout', ['url' => $url], Logger::DEBUG);
self::$istimeout = true; self::$istimeout = true;
return false; return [];
} elseif ($connection_error && $ssl_connection_error) { } elseif ($connection_error && $ssl_connection_error) {
self::$istimeout = true; self::$istimeout = true;
return false; return [];
} }
$xml = $curlResult->getBody(); $xml = $curlResult->getBody();
@ -340,9 +340,9 @@ class Probe
} }
} }
if (!is_array($webfinger["links"])) { if (empty($webfinger["links"])) {
Logger::log("No webfinger links found for ".$uri, Logger::DEBUG); Logger::log("No webfinger links found for ".$uri, Logger::DEBUG);
return false; return [];
} }
$data = []; $data = [];
@ -397,7 +397,7 @@ class Probe
$ap_profile = ActivityPub::probeProfile($uri); $ap_profile = ActivityPub::probeProfile($uri);
if (empty($data) || (!empty($ap_profile) && empty($network) && (($data['network'] ?? '') != Protocol::DFRN))) { if (empty($data) || (!empty($ap_profile) && empty($network) && (($data['network'] ?? '') != Protocol::DFRN))) {
$subscribe = $data['subscribe']; $subscribe = $data['subscribe'] ?? '';
$data = $ap_profile; $data = $ap_profile;
$data['subscribe'] = $subscribe; $data['subscribe'] = $subscribe;
} elseif (!empty($ap_profile)) { } elseif (!empty($ap_profile)) {
@ -928,15 +928,15 @@ class Probe
$curlResult = Network::curl($url, false, ['timeout' => $xrd_timeout, 'accept_content' => $type]); $curlResult = Network::curl($url, false, ['timeout' => $xrd_timeout, 'accept_content' => $type]);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
self::$istimeout = true; self::$istimeout = true;
return false; return [];
} }
$data = $curlResult->getBody(); $data = $curlResult->getBody();
$webfinger = json_decode($data, true); $webfinger = json_decode($data, true);
if (is_array($webfinger)) { if (!empty($webfinger)) {
if (!isset($webfinger["links"])) { if (!isset($webfinger["links"])) {
Logger::log("No json webfinger links for ".$url, Logger::DEBUG); Logger::log("No json webfinger links for ".$url, Logger::DEBUG);
return false; return [];
} }
return $webfinger; return $webfinger;
} }
@ -945,13 +945,13 @@ class Probe
$xrd = XML::parseString($data, true); $xrd = XML::parseString($data, true);
if (!is_object($xrd)) { if (!is_object($xrd)) {
Logger::log("No webfinger data retrievable for ".$url, Logger::DEBUG); Logger::log("No webfinger data retrievable for ".$url, Logger::DEBUG);
return false; return [];
} }
$xrd_arr = XML::elementToArray($xrd); $xrd_arr = XML::elementToArray($xrd);
if (!isset($xrd_arr["xrd"]["link"])) { if (!isset($xrd_arr["xrd"]["link"])) {
Logger::log("No XML webfinger links for ".$url, Logger::DEBUG); Logger::log("No XML webfinger links for ".$url, Logger::DEBUG);
return false; return [];
} }
$webfinger = []; $webfinger = [];
@ -997,18 +997,18 @@ class Probe
$curlResult = Network::curl($noscrape_url); $curlResult = Network::curl($noscrape_url);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
self::$istimeout = true; self::$istimeout = true;
return false; return [];
} }
$content = $curlResult->getBody(); $content = $curlResult->getBody();
if (!$content) { if (!$content) {
Logger::log("Empty body for ".$noscrape_url, Logger::DEBUG); Logger::log("Empty body for ".$noscrape_url, Logger::DEBUG);
return false; return [];
} }
$json = json_decode($content, true); $json = json_decode($content, true);
if (!is_array($json)) { if (!is_array($json)) {
Logger::log("No json data for ".$noscrape_url, Logger::DEBUG); Logger::log("No json data for ".$noscrape_url, Logger::DEBUG);
return false; return [];
} }
if (!empty($json["fn"])) { if (!empty($json["fn"])) {
@ -1218,7 +1218,7 @@ class Probe
} }
if (!isset($data["network"]) || ($hcard_url == "")) { if (!isset($data["network"]) || ($hcard_url == "")) {
return false; return [];
} }
// Fetch data via noscrape - this is faster // Fetch data via noscrape - this is faster
@ -1255,23 +1255,23 @@ class Probe
$curlResult = Network::curl($hcard_url); $curlResult = Network::curl($hcard_url);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
self::$istimeout = true; self::$istimeout = true;
return false; return [];
} }
$content = $curlResult->getBody(); $content = $curlResult->getBody();
if (!$content) { if (!$content) {
return false; return [];
} }
$doc = new DOMDocument(); $doc = new DOMDocument();
if (!@$doc->loadHTML($content)) { if (!@$doc->loadHTML($content)) {
return false; return [];
} }
$xpath = new DomXPath($doc); $xpath = new DomXPath($doc);
$vcards = $xpath->query("//div[contains(concat(' ', @class, ' '), ' vcard ')]"); $vcards = $xpath->query("//div[contains(concat(' ', @class, ' '), ' vcard ')]");
if (!is_object($vcards)) { if (!is_object($vcards)) {
return false; return [];
} }
if (!isset($data["baseurl"])) { if (!isset($data["baseurl"])) {
@ -1409,7 +1409,7 @@ class Probe
} }
if (empty($data["url"]) || empty($hcard_url)) { if (empty($data["url"]) || empty($hcard_url)) {
return false; return [];
} }
if (!empty($webfinger["aliases"]) && is_array($webfinger["aliases"])) { if (!empty($webfinger["aliases"]) && is_array($webfinger["aliases"])) {
@ -1430,7 +1430,7 @@ class Probe
$data = self::pollHcard($hcard_url, $data); $data = self::pollHcard($hcard_url, $data);
if (!$data) { if (!$data) {
return false; return [];
} }
if (!empty($data["url"]) if (!empty($data["url"])
@ -1450,7 +1450,7 @@ class Probe
$data["notify"] = $data["baseurl"] . "/receive/users/" . $data["guid"]; $data["notify"] = $data["baseurl"] . "/receive/users/" . $data["guid"];
$data["batch"] = $data["baseurl"] . "/receive/public"; $data["batch"] = $data["baseurl"] . "/receive/public";
} else { } else {
return false; return [];
} }
return $data; return $data;
@ -1483,7 +1483,7 @@ class Probe
$data["addr"] = str_replace('acct:', '', $webfinger["subject"]); $data["addr"] = str_replace('acct:', '', $webfinger["subject"]);
} }
if (is_array($webfinger["links"])) { if (!empty($webfinger["links"])) {
// The array is reversed to take into account the order of preference for same-rel links // The array is reversed to take into account the order of preference for same-rel links
// See: https://tools.ietf.org/html/rfc7033#section-4.4.4 // See: https://tools.ietf.org/html/rfc7033#section-4.4.4
foreach (array_reverse($webfinger["links"]) as $link) { foreach (array_reverse($webfinger["links"]) as $link) {
@ -1509,7 +1509,7 @@ class Probe
$curlResult = Network::curl($pubkey); $curlResult = Network::curl($pubkey);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
self::$istimeout = true; self::$istimeout = true;
return false; return $short ? false : [];
} }
$pubkey = $curlResult->getBody(); $pubkey = $curlResult->getBody();
} }
@ -1531,7 +1531,7 @@ class Probe
) { ) {
$data["network"] = Protocol::OSTATUS; $data["network"] = Protocol::OSTATUS;
} else { } else {
return false; return $short ? false : [];
} }
if ($short) { if ($short) {
@ -1542,12 +1542,12 @@ class Probe
$curlResult = Network::curl($data["poll"]); $curlResult = Network::curl($data["poll"]);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
self::$istimeout = true; self::$istimeout = true;
return false; return [];
} }
$feed = $curlResult->getBody(); $feed = $curlResult->getBody();
$feed_data = Feed::import($feed); $feed_data = Feed::import($feed);
if (!$feed_data) { if (!$feed_data) {
return false; return [];
} }
if (!empty($feed_data["header"]["author-name"])) { if (!empty($feed_data["header"]["author-name"])) {
@ -1594,12 +1594,12 @@ class Probe
{ {
$curlResult = Network::curl($profile_link); $curlResult = Network::curl($profile_link);
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
return false; return [];
} }
$doc = new DOMDocument(); $doc = new DOMDocument();
if (!@$doc->loadHTML($curlResult->getBody())) { if (!@$doc->loadHTML($curlResult->getBody())) {
return false; return [];
} }
$xpath = new DomXPath($doc); $xpath = new DomXPath($doc);
@ -1680,13 +1680,13 @@ class Probe
$data["network"] = Protocol::PUMPIO; $data["network"] = Protocol::PUMPIO;
} else { } else {
return false; return [];
} }
$profile_data = self::pumpioProfileData($data["url"]); $profile_data = self::pumpioProfileData($data["url"]);
if (!$profile_data) { if (!$profile_data) {
return false; return [];
} }
$data = array_merge($data, $profile_data); $data = array_merge($data, $profile_data);
@ -1859,20 +1859,20 @@ class Probe
$curlResult = Network::curl($url); $curlResult = Network::curl($url);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
self::$istimeout = true; self::$istimeout = true;
return false; return [];
} }
$feed = $curlResult->getBody(); $feed = $curlResult->getBody();
$feed_data = Feed::import($feed); $feed_data = Feed::import($feed);
if (!$feed_data) { if (!$feed_data) {
if (!$probe) { if (!$probe) {
return false; return [];
} }
$feed_url = self::getFeedLink($url, $feed); $feed_url = self::getFeedLink($url, $feed);
if (!$feed_url) { if (!$feed_url) {
return false; return [];
} }
return self::feed($feed_url, false); return self::feed($feed_url, false);
@ -1920,11 +1920,11 @@ class Probe
private static function mail($uri, $uid) private static function mail($uri, $uid)
{ {
if (!Network::isEmailDomainValid($uri)) { if (!Network::isEmailDomainValid($uri)) {
return false; return [];
} }
if ($uid == 0) { if ($uid == 0) {
return false; return [];
} }
$user = DBA::selectFirst('user', ['prvkey'], ['uid' => $uid]); $user = DBA::selectFirst('user', ['prvkey'], ['uid' => $uid]);
@ -1934,7 +1934,7 @@ class Probe
$mailacct = DBA::selectFirst('mailacct', $fields, $condition); $mailacct = DBA::selectFirst('mailacct', $fields, $condition);
if (!DBA::isResult($user) || !DBA::isResult($mailacct)) { if (!DBA::isResult($user) || !DBA::isResult($mailacct)) {
return false; return [];
} }
$mailbox = Email::constructMailboxName($mailacct); $mailbox = Email::constructMailboxName($mailacct);
@ -1942,14 +1942,14 @@ class Probe
openssl_private_decrypt(hex2bin($mailacct['pass']), $password, $user['prvkey']); openssl_private_decrypt(hex2bin($mailacct['pass']), $password, $user['prvkey']);
$mbox = Email::connect($mailbox, $mailacct['user'], $password); $mbox = Email::connect($mailbox, $mailacct['user'], $password);
if (!$mbox) { if (!$mbox) {
return false; return [];
} }
$msgs = Email::poll($mbox, $uri); $msgs = Email::poll($mbox, $uri);
Logger::log('searching '.$uri.', '.count($msgs).' messages found.', Logger::DEBUG); Logger::log('searching '.$uri.', '.count($msgs).' messages found.', Logger::DEBUG);
if (!count($msgs)) { if (!count($msgs)) {
return false; return [];
} }
$phost = substr($uri, strpos($uri, '@') + 1); $phost = substr($uri, strpos($uri, '@') + 1);