mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-30 17:23:23 -05:00
put a hard limit to packet size in pqistore to avoid calling realloc with fancy numbers when the stream has been corrupted
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7049 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
43a32f23e1
commit
1f4580304f
@ -308,12 +308,21 @@ int pqistore::readPkt(RsItem **item_out)
|
|||||||
int extralen = getRsItemSize(block) - blen;
|
int extralen = getRsItemSize(block) - blen;
|
||||||
int totallen = extralen+blen;
|
int totallen = extralen+blen;
|
||||||
|
|
||||||
|
// make sure that totallen is not a crazy number. If so, we drop the entire stream that might be corrupted.
|
||||||
|
|
||||||
|
if(totallen > 1024*1024)
|
||||||
|
{
|
||||||
|
std::cerr << "pqistore: ERROR: trying to realloc memory for packet of length" << totallen <<", which exceeds the allowed limit (1MB)" << std::endl ;
|
||||||
|
free(block) ;
|
||||||
|
bStopReading=true;
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
void *tmp = realloc(block, totallen);
|
void *tmp = realloc(block, totallen);
|
||||||
|
|
||||||
if (tmp == NULL)
|
if (tmp == NULL)
|
||||||
{
|
{
|
||||||
free(block);
|
free(block);
|
||||||
std::cerr << "pqistore: ERROR: trying to realloc memory for packet of length" << extralen+blen << std::endl ;
|
std::cerr << "pqistore: ERROR: trying to realloc memory for packet of length" << totallen << std::endl ;
|
||||||
std::cerr << "Have you got enought memory?" << std::endl ;
|
std::cerr << "Have you got enought memory?" << std::endl ;
|
||||||
bStopReading=true;
|
bStopReading=true;
|
||||||
return 0 ;
|
return 0 ;
|
||||||
@ -506,8 +515,17 @@ int pqiSSLstore::readPkt(RsItem **item_out)
|
|||||||
int extralen = getRsItemSize(block) - blen;
|
int extralen = getRsItemSize(block) - blen;
|
||||||
int totallen = extralen+blen;
|
int totallen = extralen+blen;
|
||||||
|
|
||||||
|
if(totallen > 1024*1024)
|
||||||
|
{
|
||||||
|
free(block);
|
||||||
|
std::cerr << "pqiSSLstore: ERROR: trying to realloc memory for packet of length" << totallen << ", that exceeds the limit of 1MB" << std::endl ;
|
||||||
|
bStopReading=true;
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
void *tmp = realloc(block, totallen);
|
void *tmp = realloc(block, totallen);
|
||||||
if (tmp == NULL) {
|
|
||||||
|
if (tmp == NULL)
|
||||||
|
{
|
||||||
free(block);
|
free(block);
|
||||||
std::cerr << "pqiSSLstore: ERROR: trying to realloc memory for packet of length" << extralen+blen << std::endl ;
|
std::cerr << "pqiSSLstore: ERROR: trying to realloc memory for packet of length" << extralen+blen << std::endl ;
|
||||||
std::cerr << "Have you got enought memory?" << std::endl ;
|
std::cerr << "Have you got enought memory?" << std::endl ;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user