avoid fatal errors when decoding advert packets
This commit is contained in:
@@ -105,6 +105,7 @@ class CoreParser {
|
|||||||
$m->pub_key = base64_encode(substr($payload, 1, CoreProtocol::PUB_KEY_SIZE));
|
$m->pub_key = base64_encode(substr($payload, 1, CoreProtocol::PUB_KEY_SIZE));
|
||||||
|
|
||||||
if( strlen($payload) > CoreProtocol::PUB_KEY_SIZE + 2 ) {
|
if( strlen($payload) > CoreProtocol::PUB_KEY_SIZE + 2 ) {
|
||||||
|
try {
|
||||||
$m->type = ord($payload[33]);
|
$m->type = ord($payload[33]);
|
||||||
$m->flags = ord($payload[34]);
|
$m->flags = ord($payload[34]);
|
||||||
$m->out_path = substr($payload, 35, CoreProtocol::MAX_PATH_SIZE);
|
$m->out_path = substr($payload, 35, CoreProtocol::MAX_PATH_SIZE);
|
||||||
@@ -114,6 +115,11 @@ class CoreParser {
|
|||||||
$m->lon = unpack('V', substr($payload, 211, 4))[1];
|
$m->lon = unpack('V', substr($payload, 211, 4))[1];
|
||||||
$m->last_mod = unpack('V', substr($payload, 215, 4))[1];
|
$m->last_mod = unpack('V', substr($payload, 215, 4))[1];
|
||||||
}
|
}
|
||||||
|
catch(\Throwable $t) {
|
||||||
|
// hidden problem? packet wasn't long enough so we'll just be missing data i suppose
|
||||||
|
error_log("Tried to decode Advert but packet too small. Packet size: " . strlen($payload) . " and expected 215..");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $m;
|
return $m;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user