From 9a8ee1aa2bf9a9668d0f0556e2e7883294424db9 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 5 Nov 2022 19:03:33 +1100 Subject: [PATCH] Fix packets with null values in the date, and exceptions not catching it --- app/Classes/FTN/Message.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/Classes/FTN/Message.php b/app/Classes/FTN/Message.php index a1c9632..5641d57 100644 --- a/app/Classes/FTN/Message.php +++ b/app/Classes/FTN/Message.php @@ -3,6 +3,7 @@ namespace App\Classes\FTN; use Carbon\Carbon; +use Carbon\Exceptions\InvalidFormatException; use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Log; @@ -10,7 +11,7 @@ use Illuminate\Support\Facades\Validator; use Illuminate\Validation\Validator as ValidatorResult; use App\Classes\FTN as FTNBase; -use App\Models\{Address,Domain,Setup,Zone}; +use App\Models\{Address,Domain,Zone}; use App\Rules\{TwoByteInteger,TwoByteIntegerWithZero}; use App\Traits\EncodeUTF8; @@ -273,12 +274,15 @@ class Message extends FTNBase case 'date': try { - return Carbon::createFromFormat('d M y H:i:s O', - sprintf('%s %s%04d',chop(Arr::get($this->header,$key)),($this->tzutc < 0) ? '-' : '+',abs($this->tzutc))); + if (str_contains($x=chop(Arr::get($this->header,$key)),"\x00")) + throw new \Exception('Date contains null values.'); - } catch (\Exception $e) { + return Carbon::createFromFormat('d M y H:i:s O', + sprintf('%s %s%04d',$x,($this->tzutc < 0) ? '-' : '+',abs($this->tzutc))); + + } catch (InvalidFormatException|\Exception $e) { Log::error(sprintf('%s: ! Date doesnt parse [%s] (%s)',self::LOGKEY,$e->getMessage(),Arr::get($this->header,$key))); - return NULL; + throw new \Exception($e->getMessage()); } case 'flags':