Fix crash in RsCertificate::fromString due to exception

Also fix warning due to deprecaded RsPeerId constructor usage
This commit is contained in:
Gioacchino Mazzurco 2019-05-02 17:34:21 +02:00
parent 13ba26251c
commit 8300e65cad
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051

View File

@ -388,7 +388,14 @@ void RsCertificate::scan_ip(const std::string& ip_string, unsigned short port,un
buf = &buf[1];
unsigned char *buf2 = buf;
uint32_t s = PGPKeyParser::read_125Size(buf);
uint32_t s = 0;
try { s = PGPKeyParser::read_125Size(buf); }
catch (...)
{
err_code = CERTIFICATE_PARSING_ERROR_SIZE_ERROR;
return nullptr;
}
total_s += 1 + (
reinterpret_cast<size_t>(buf) -
@ -425,7 +432,8 @@ void RsCertificate::scan_ip(const std::string& ip_string, unsigned short port,un
err_code = CERTIFICATE_PARSING_ERROR_INVALID_LOCATION_ID;
return nullptr;
}
crt->location_id = RsPeerId(buf);
// We just checked buffer size so next line is not unsafe
crt->location_id = RsPeerId::fromBufferUnsafe(buf);
crt->only_pgp = false;
break;
case CERTIFICATE_PTAG_DNS_SECTION: