From aeef4960a1191d62c4cbdd6cc0e67d1c19ae9b84 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 11 May 2021 08:10:25 -0400 Subject: [PATCH] Make birthday time comparison 32-bit safe in Protocol\DFRN - Address https://github.com/friendica/friendica/issues/10168#issuecomment-838221234 --- src/Protocol/DFRN.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index df974729ba..d20b8949b8 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -1441,19 +1441,19 @@ class DFRN /** * Fetch the author data from head or entry items * - * @param object $xpath XPath object - * @param object $context In which context should the data be searched - * @param array $importer Record of the importer user mixed with contact of the content - * @param string $element Element name from which the data is fetched - * @param bool $onlyfetch Should the data only be fetched or should it update the contact record as well - * @param string $xml optional, default empty + * @param \DOMXPath $xpath XPath object + * @param \DOMNode $context In which context should the data be searched + * @param array $importer Record of the importer user mixed with contact of the content + * @param string $element Element name from which the data is fetched + * @param bool $onlyfetch Should the data only be fetched or should it update the contact record as well + * @param string $xml optional, default empty * * @return array Relevant data of the author * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException * @todo Find good type-hints for all parameter */ - private static function fetchauthor($xpath, $context, $importer, $element, $onlyfetch, $xml = "") + private static function fetchauthor(\DOMXPath $xpath, \DOMNode $context, $importer, $element, $onlyfetch, $xml = "") { $author = []; $author["name"] = XML::getFirstNodeValue($xpath, $element."/atom:name/text()", $context); @@ -1609,12 +1609,14 @@ class DFRN } // "dfrn:birthday" contains the birthday converted to UTC - $birthday = XML::getFirstNodeValue($xpath, $element . "/poco:birthday/text()", $context); - - if (strtotime($birthday) > time()) { - $bd_timestamp = strtotime($birthday); - - $poco["bdyear"] = date("Y", $bd_timestamp); + $birthday = XML::getFirstNodeValue($xpath, $element . "/dfrn:birthday/text()", $context); + try { + $birthday_date = new \DateTime($birthday); + if ($birthday_date > new \DateTime()) { + $poco["bdyear"] = $birthday_date->format("Y"); + } + } catch (\Exception $e) { + // Invalid birthday } // "poco:birthday" is the birthday in the format "yyyy-mm-dd"