Fix for when packets contain binary messages with SOH chars. Added testing for packet parsing

This commit is contained in:
Deon George
2021-11-28 14:02:50 +11:00
parent e0239d95a8
commit 880ff81eff
3 changed files with 92 additions and 27 deletions

View File

@@ -385,6 +385,7 @@ class Message extends FTNBase
case 'seenaddress':
case 'rogue_path':
case 'rogue_seen':
case 'unknown':
case 'via':
case 'errors':
@@ -679,24 +680,36 @@ class Message extends FTNBase
$this->message = '';
$this->message_src = '';
$srcpos = 0;
$msgpos = 0;
foreach ($result as $kl) {
// $kl is our line starting with a \x01 kludge delimiter
foreach ($result as $v) {
// Search for \r - if that is the end of the line, then its a kludge
$x = strpos($v,"\r");
$retpos = strpos($kl,"\r");
$msgpos += 1+strlen($kl); // SOH+text
$t = '';
$srcpos += 1+$x+1; // SOH+text+\r
// If there are more characters, then put the kludge back into the result, so that we process it.
if ($x != strlen($v)-1) {
// If there are is a return in this middle of this line, that means the text message starts after the return
// If our message has started, then we'll assume the binary is part of the message.
if (strlen($this->message) || ($retpos != strlen($kl)-1)) {
// Anything after the origin line is also kludge data.
if ($y = strpos($v,"\r * Origin: ")) {
$this->message .= substr($v,$x+1,$y-$x-1);
$this->parseOrigin(substr($v,$y));
if (($originpos = strpos($kl,"\r * Origin: "))) {
if (! $this->message) {
$this->message .= substr($kl,$retpos+1,$originpos-$retpos-1);
$this->parseOrigin(substr($kl,$originpos+1));
$kl = substr($kl,0,$retpos);
// Capture the raw message, in case we send it on
// length = src, remove current 1+$x+1, add soh, $y + origin_start + origin_length + 0d
$this->message_src .= substr($message,0,$srcpos-(1+$x+1)+1+$y+12+strlen($this->origin)+1);
$this->message_src = substr($message, 0, $msgpos - strlen($kl) + 9);
} else {
$this->message .= "\x01".substr($kl,0,$originpos);
$this->parseOrigin(substr($kl,$originpos+1));
// Capture the raw message, in case we send it on
$this->message_src = substr($message, 0, $msgpos - strlen($kl) - 1 + $originpos + 12 + strlen($this->origin) + 1);
$kl = '';
}
// If this is netmail, the FQFA will have been set by the INTL line, we can skip the rest of this
$matches = [];
@@ -719,16 +732,17 @@ class Message extends FTNBase
}
// The message is the rest?
} elseif (strlen($v) > $x+1) {
$this->message .= substr($v,$x+1);
$this->message_src .= substr($v,$x+1);
} elseif (strlen($kl) > $retpos+1) {
$this->message .= substr($kl,$retpos+1);
$kl = substr($kl,0,$retpos);
}
$v = substr($v,0,$x+1);
if (! $kl)
continue;
}
foreach ($this->_kludge as $a => $b) {
if ($t = $this->kludge($b,$v)) {
if ($t = $this->kludge($b,$kl)) {
$this->kludge->put($a,$t);
break;
}
@@ -739,7 +753,7 @@ class Message extends FTNBase
continue;
// From point: <SOH>"FMPT <point number><CR>
if ($t = $this->kludge('FMPT ',$v))
if ($t = $this->kludge('FMPT ',$kl))
$this->point['src'] = $t;
/*
@@ -749,7 +763,7 @@ class Message extends FTNBase
*
* <SOH>"INTL "<destination address>" "<origin address><CR>
*/
elseif ($t = $this->kludge('INTL ',$v)) {
elseif ($t = $this->kludge('INTL ',$kl)) {
$this->intl = $t;
// INTL kludge is in Netmail, so we'll do some validation:
@@ -766,32 +780,32 @@ class Message extends FTNBase
}
}
elseif ($t = $this->kludge('TZUTC: ',$v))
elseif ($t = $this->kludge('TZUTC: ',$kl))
$this->tzutc = $t;
elseif ($t = $this->kludge('MSGID: ',$v))
elseif ($t = $this->kludge('MSGID: ',$kl))
$this->msgid = $t;
elseif ($t = $this->kludge('PATH: ',$v))
elseif ($t = $this->kludge('PATH: ',$kl))
$this->path->push($t);
elseif ($t = $this->kludge('RESCANNED ',$v))
elseif ($t = $this->kludge('RESCANNED ',$kl))
$this->rescanned->push($t);
elseif ($t = $this->kludge('SEEN-BY: ',$v))
elseif ($t = $this->kludge('SEEN-BY: ',$kl))
$this->seenby->push($t);
// To Point: <SOH>TOPT <point number><CR>
elseif ($t = $this->kludge('TOPT ',$v))
elseif ($t = $this->kludge('TOPT ',$kl))
$this->point['dst'] = $t;
// <SOH>Via <FTN Address> @YYYYMMDD.HHMMSS[.Precise][.Time Zone] <Program Name> <Version> [Serial Number]<CR>
elseif ($t = $this->kludge('Via ',$v))
elseif ($t = $this->kludge('Via ',$kl))
$this->via->push($t);
// We got a kludge line we dont know about
else
$this->unknown->push(chop($v,"\r"));
$this->unknown->push(chop($kl,"\r"));
}
// Work out our zone/point