fixed a few things to correct PR403

This commit is contained in:
csoler 2016-06-02 20:23:22 -04:00
parent 699b3cf064
commit 10e0254317
8 changed files with 59 additions and 19 deletions

View File

@ -532,12 +532,18 @@ bool RsGRouterTransactionAcknItem::serialise(void *data,uint32_t& size) const
return ok;
}
bool RsGRouterGenericDataItem::serialise_signed_data(void *data,uint32_t& size) const
bool RsGRouterGenericDataItem::serialise_signed_data(void *data,uint32_t size) const
{
bool ok = true;
uint32_t offset = 0;
uint32_t tlvsize = signed_data_size() ;
if(tlvsize > size)
{
ok = false;
std::cerr << "RsGRouterReceiptItem::serialisedata() size error! Not enough size in supplied container." << std::endl;
}
/* add mandatory parts first */
ok &= setRawUInt64(data, tlvsize, &offset, routing_id);
@ -580,12 +586,18 @@ bool RsGRouterSignedReceiptItem::serialise(void *data,uint32_t& size) const
return ok;
}
bool RsGRouterSignedReceiptItem::serialise_signed_data(void *data,uint32_t& size) const
bool RsGRouterSignedReceiptItem::serialise_signed_data(void *data,uint32_t size) const
{
bool ok = true;
uint32_t offset=0;
uint32_t tlvsize = signed_data_size() ;
if(tlvsize > size)
{
ok = false;
std::cerr << "RsGRouterReceiptItem::serialisedata() size error! Not enough size in supplied container." << std::endl;
}
/* add mandatory parts first */
ok &= setRawUInt64(data, tlvsize, &offset, routing_id);

View File

@ -101,7 +101,7 @@ public:
virtual ~RsGRouterAbstractMsgItem() {}
virtual uint32_t signed_data_size() const = 0 ;
virtual bool serialise_signed_data(void *data,uint32_t& size) const = 0 ;
virtual bool serialise_signed_data(void *data,uint32_t size) const = 0 ;
GRouterMsgPropagationId routing_id ;
GRouterKeyId destination_key ;
@ -137,7 +137,7 @@ class RsGRouterGenericDataItem: public RsGRouterAbstractMsgItem, public RsGRoute
// utility methods for signing data
virtual uint32_t signed_data_size() const ;
virtual bool serialise_signed_data(void *data,uint32_t& size) const ;
virtual bool serialise_signed_data(void *data, uint32_t size) const ;
};
class RsGRouterSignedReceiptItem: public RsGRouterAbstractMsgItem
@ -160,7 +160,7 @@ class RsGRouterSignedReceiptItem: public RsGRouterAbstractMsgItem
// utility methods for signing data
virtual uint32_t signed_data_size() const ;
virtual bool serialise_signed_data(void *data,uint32_t& size) const ;
virtual bool serialise_signed_data(void *data, uint32_t size) const ;
};
// Low-level data items

View File

@ -289,7 +289,7 @@ bool RsGxsIntegrityCheck::check()
// now request a cache update for them, which triggers downloading from friends, if missing.
for(;nb_requested_not_in_cache<MAX_GXS_IDS_REQUESTS_NET && gxs_ids.size()>0;)
for(;nb_requested_not_in_cache<MAX_GXS_IDS_REQUESTS_NET && !gxs_ids.empty();)
{
uint32_t n = RSRandom::random_u32() % gxs_ids.size() ;
#ifdef GXSUTIL_DEBUG

View File

@ -378,6 +378,12 @@ RsGxsTunnelDataItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelDataItem(void
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(dat);
bool ok = true ;
if(rssize > size)
{
std::cerr << "RsGxsTunnelDataItem::() Size error while deserializing." << std::endl ;
return false ;
}
RsGxsTunnelDataItem *item = new RsGxsTunnelDataItem();
@ -388,9 +394,9 @@ RsGxsTunnelDataItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelDataItem(void
ok &= getRawUInt32(dat, rssize, &offset, &item->service_id);
ok &= getRawUInt32(dat, rssize, &offset, &item->data_size);
if(item->data_size > rssize || rssize - item->data_size < offset)
if(item->data_size > rssize || rssize < offset + item->data_size)
{
std::cerr << "RsGxsTunnelDHPublicKeyItem::() Size error while deserializing." << std::endl ;
std::cerr << "RsGxsTunnelDataItem::() Size error while deserializing." << std::endl ;
delete item ;
return NULL ;
}
@ -456,6 +462,12 @@ RsGxsTunnelStatusItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelStatusItem(
uint32_t rssize = getRsItemSize(dat);
bool ok = true ;
if(rssize > size)
{
std::cerr << "RsGxsTunnelStatusItem::() Size error while deserializing." << std::endl ;
return false ;
}
RsGxsTunnelStatusItem *item = new RsGxsTunnelStatusItem();
/* get mandatory parts first */
@ -464,13 +476,13 @@ RsGxsTunnelStatusItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelStatusItem(
if (offset != rssize)
{
std::cerr << "RsGxsTunnelDHPublicKeyItem::() Size error while deserializing." << std::endl ;
std::cerr << "RsGxsTunnelStatusItem::() Size error while deserializing." << std::endl ;
delete item ;
return NULL ;
}
if (!ok)
{
std::cerr << "RsGxsTunnelDHPublicKeyItem::() Unknown error while deserializing." << std::endl ;
std::cerr << "RsGxsTunnelStatusItem::() Unknown error while deserializing." << std::endl ;
delete item ;
return NULL ;
}

View File

@ -133,6 +133,12 @@ public:
uint32_t rssize = getRsItemSize(data);
bool ok = true ;
if(rssize > size)
{
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
return NULL ;
}
/* add mandatory parts first */
ok &= getRawUInt32(data, rssize, &offset, &item->mServiceId);
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->mServiceName);

View File

@ -170,7 +170,7 @@ uint64_t BinFileInterface::bytecount()
return 0;
}
int BinFileInterface::getFileSize()
uint64_t BinFileInterface::getFileSize()
{
return size;
}
@ -229,7 +229,14 @@ int BinEncryptedFileInterface::readdata(void* data, int len)
if(!haveData) // read whole data for first call, or first call after close()
{
encrypDataLen = BinFileInterface::getFileSize();
uint64_t encrypDataLen64 = BinFileInterface::getFileSize();
if(encrypDataLen64 > uint64_t(~(int)0))
{
std::cerr << __PRETTY_FUNCTION__ << ": cannot decrypt files of size > " << ~(int)0 << std::endl;
return -1 ;
}
encrypDataLen = (int)encrypDataLen64 ;
encryptedData = new char[encrypDataLen];
// make sure assign was successful
@ -245,12 +252,15 @@ int BinEncryptedFileInterface::readdata(void* data, int len)
if((encrypDataLen > 0) && (encryptedData != NULL))
{
if(!AuthSSL::getAuthSSL()->decrypt((void*&)(this->data), sizeData, encryptedData, encrypDataLen))
int sizeDataInt = 0 ;
if(!AuthSSL::getAuthSSL()->decrypt((void*&)(this->data), sizeDataInt, encryptedData, encrypDataLen))
{
delete[] encryptedData;
return -1;
}
sizeData = sizeDataInt ;
haveData = true;
delete[] encryptedData;
}

View File

@ -76,12 +76,12 @@ virtual RsFileHash gethash();
virtual uint64_t bytecount();
protected:
virtual int getFileSize();
virtual uint64_t getFileSize();
private:
int bin_flags;
FILE *buf;
int size;
uint64_t size;
pqihash *hash;
uint64_t bcount;
};
@ -127,7 +127,7 @@ private:
char* data;
bool haveData;
int sizeData;
uint64_t sizeData;
uint64_t cpyCount;
};

View File

@ -1043,7 +1043,7 @@ bool p3GxsCircles::cache_load_for_token(uint32_t token)
bool p3GxsCircles::locked_processLoadingCacheEntry(RsGxsCircleCache& cache)
{
bool isUnprocessedPeers = false;
//bool isUnprocessedPeers = false;
if (cache.mIsExternal)
{
@ -1086,7 +1086,7 @@ bool p3GxsCircles::locked_processLoadingCacheEntry(RsGxsCircleCache& cache)
}
mIdentities->requestKey(pit->first, peers);
isUnprocessedPeers = true;
//isUnprocessedPeers = true;
}
#ifdef DEBUG_CIRCLES
else