Fix crash in p3Peers::loadCertificateFromString

This function is part of the public API so it must be safe to call with
any input, before this commit if would crash if feeded with a broken or
empty certificate radix string.
This commit is contained in:
Gioacchino Mazzurco 2018-10-12 22:28:44 +02:00
parent fc14300b06
commit 15b729b35c
No known key found for this signature in database
GPG key ID: A1FBCA3872E87051
3 changed files with 113 additions and 65 deletions

View file

@ -1213,17 +1213,27 @@ std::string p3Peers::GetRetroshareInvite(
//===========================================================================
bool p3Peers::loadCertificateFromString(const std::string& cert, RsPeerId& ssl_id, RsPgpId& gpg_id, std::string& error_string)
bool p3Peers::loadCertificateFromString(
const std::string& cert, RsPeerId& ssl_id,
RsPgpId& gpg_id, std::string& error_string )
{
RsCertificate crt(cert) ;
RsPgpId gpgid ;
RsCertificate crt;
uint32_t errNum = 0;
if(!crt.initializeFromString(cert,errNum))
{
error_string = "RsCertificate failed with errno: "
+ std::to_string(errNum) + " parsing: " + cert;
return false;
}
bool res = AuthGPG::getAuthGPG()->LoadCertificateFromString(crt.armouredPGPKey(),gpgid,error_string) ;
RsPgpId gpgid;
bool res = AuthGPG::getAuthGPG()->
LoadCertificateFromString(crt.armouredPGPKey(), gpgid,error_string);
gpg_id = gpgid;
ssl_id = crt.sslid() ;
ssl_id = crt.sslid();
return res ;
return res;
}
bool p3Peers::loadDetailsFromStringCert( const std::string &certstr,