security check for encryption key length to avoid crashing when deserialisation gives wrong numbers

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7535 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2014-09-14 19:23:23 +00:00
parent f3aeaea526
commit 9752fb9698

View File

@ -452,6 +452,14 @@ bool GxsSecurity::decrypt(uint8_t *& out, int & outlen, const uint8_t *in, int i
eklen = ntohl(net_ekl);
in_offset += size_net_ekl;
// Conservative limits to detect weird errors due to corrupted encoding.
//
if(eklen < 0 || eklen > 512 || eklen+in_offset > inlen)
{
std::cerr << "Error while deserialising encryption key length: eklen = " << std::dec << eklen << ". Giving up decryption." << std::endl;
return false ;
}
memcpy(ek, (unsigned char*)in + in_offset, eklen);
in_offset += eklen;