BanEntry: work around stupid bug in ext/date

https://bugs.php.net/bug.php?id=75992

When plugins do time-limited bans and users enter stupid time values, a shitty bug in ext/date gets triggered, but only when reading the ban entries from disk. DateTime->format() is able to produce formatted strings which have more than 4 digits in the year, which are then considered invalid. This works around it by trying to parse a formatted version on the fly to ensure that it is valid.

This also cleans up and improves ban list loading and handling.
This commit is contained in:
Dylan K. Taylor
2018-02-22 14:48:53 +00:00
parent aa11dbb928
commit 37e8c8d324
2 changed files with 66 additions and 22 deletions

View File

@ -147,9 +147,15 @@ class BanList{
if(is_resource($fp)){
while(($line = fgets($fp)) !== false){
if($line{0} !== "#"){
$entry = BanEntry::fromString($line);
if($entry instanceof BanEntry){
$this->list[$entry->getName()] = $entry;
try{
$entry = BanEntry::fromString($line);
if($entry instanceof BanEntry){
$this->list[$entry->getName()] = $entry;
}
}catch(\Throwable $e){
$logger = MainLogger::getLogger();
$logger->critical("Failed to parse ban entry from string \"$line\": " . $e->getMessage());
$logger->logException($e);
}
}
}