From bf57f151d5988c323832a65042789a7ee4aaaf91 Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 1 Dec 2021 23:41:20 +1100 Subject: [PATCH] Attempt to catch invalid FTN addresses while parsing packets --- app/Classes/FTN/Message.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/Classes/FTN/Message.php b/app/Classes/FTN/Message.php index aafdb25..e3f3228 100644 --- a/app/Classes/FTN/Message.php +++ b/app/Classes/FTN/Message.php @@ -730,7 +730,11 @@ class Message extends FTNBase } else { // Double check, our src and origin match - $this->src = Address::parseFTN($matches[1]); + try { + $this->src = Address::parseFTN($matches[1]); + } catch (\Exception $e) { + Log::error(sprintf('%s:! Origin line address [%s] is invalid [%s]',self::LOGKEY,$this->origin,$e->getMessage())); + } } // We'll double check our FTN @@ -819,8 +823,12 @@ class Message extends FTNBase // http://ftsc.org/docs/fsc-0068.001 // MSGID should be the basis of the source, we'll overrite our src from origin if we have it $m = []; - if ($this->msgid && preg_match('#([0-9]+:[0-9]+/[0-9]+)?\.?([0-9]+)?@?([A-Za-z-_~]+)?\ +#',$this->msgid,$m)) { - $this->src = Address::parseFTN($m[1].((isset($m[2]) && $m[2] != '') ? '.'.$m[2] : '').(isset($m[3]) ? '@'.$m[3] : '')); + if ($this->msgid && preg_match('#([0-9]+:[0-9]+/[0-9]+)?\.?([0-9]+)?(\.[0-9]+)?@?([A-Za-z-_~]+)?\ +#',$this->msgid,$m)) { + try { + $this->src = Address::parseFTN($m[1].((isset($m[2]) && $m[2] != '') ? '.'.$m[2] : '').(isset($m[4]) ? '@'.$m[4] : '')); + } catch (\Exception $e) { + Log::error(sprintf('%s:! MSGID [%s] address is invalid [%s]',self::LOGKEY,$this->msgid,$e->getMessage())); + } // Without a MSGID, get our domain from the origin } elseif ($this->origin && preg_match('#\(([0-9]+:[0-9]+/[0-9]+)?\.?([0-9]+)?@?([A-Za-z-_~]+)?\)$#',$this->origin,$m)) { @@ -830,7 +838,6 @@ class Message extends FTNBase } elseif ($this->zone) { $this->src = Address::parseFTN(sprintf('%d:%d/%d.%d@%s',$this->zone->zone_id,$this->fn,$this->ff,$this->fp,$this->zone->domain->name)); } - // Parse SEEN-BY if ($this->seenby->count()) $this->seenaddress = $this->parseAddresses('seenby',$this->seenby,$this->rogue_seen);