diff --git a/libretroshare/src/grouter/p3grouter.cc b/libretroshare/src/grouter/p3grouter.cc index db7ccdd5e..e201d5924 100644 --- a/libretroshare/src/grouter/p3grouter.cc +++ b/libretroshare/src/grouter/p3grouter.cc @@ -1235,7 +1235,7 @@ bool p3GRouter::encryptDataItem(RsGRouterGenericDataItem *item,const RsGxsId& de return false ; } - delete[] item->data_bytes ; + free(item->data_bytes) ; item->data_bytes = encrypted_data ; item->data_size = encrypted_size ; item->flags |= RS_GROUTER_DATA_FLAGS_ENCRYPTED ; @@ -1279,7 +1279,7 @@ bool p3GRouter::decryptDataItem(RsGRouterGenericDataItem *item) return false ; } - delete[] item->data_bytes ; + free(item->data_bytes) ; item->data_bytes = decrypted_data ; item->data_size = decrypted_size ; item->flags &= ~RS_GROUTER_DATA_FLAGS_ENCRYPTED ; @@ -1410,7 +1410,7 @@ bool p3GRouter::cancel(GRouterMsgPropagationId mid) return true ; } -bool p3GRouter::sendData(const RsGxsId& destination,const GRouterServiceId& client_id,uint8_t *data, uint32_t data_size,const RsGxsId& signing_id, GRouterMsgPropagationId &propagation_id) +bool p3GRouter::sendData(const RsGxsId& destination,const GRouterServiceId& client_id,const uint8_t *data, uint32_t data_size,const RsGxsId& signing_id, GRouterMsgPropagationId &propagation_id) { if(data_size > MAX_GROUTER_DATA_SIZE) { @@ -1428,7 +1428,9 @@ bool p3GRouter::sendData(const RsGxsId& destination,const GRouterServiceId& clie RsGRouterGenericDataItem *data_item = new RsGRouterGenericDataItem ; - data_item->data_bytes = data ; + data_item->data_bytes = (uint8_t*)malloc(data_size) ; + memcpy(data_item->data_bytes,data,data_size) ; + data_item->data_size = data_size ; data_item->routing_id = propagation_id ; data_item->randomized_distance = 0 ; diff --git a/libretroshare/src/grouter/p3grouter.h b/libretroshare/src/grouter/p3grouter.h index 0a3ce129c..c821f1b28 100644 --- a/libretroshare/src/grouter/p3grouter.h +++ b/libretroshare/src/grouter/p3grouter.h @@ -122,8 +122,9 @@ public: // the memory. That means item_data will be erase on return. The returned id should be // remembered by the client, so that he knows when the data has been received. // The client id is supplied so that the client can be notified when the data has been received. + // Data is not modified by the global router. // - virtual bool sendData(const RsGxsId& destination, const GRouterServiceId& client_id, uint8_t *data, uint32_t data_size, const RsGxsId& signing_id, GRouterMsgPropagationId& id) ; + virtual bool sendData(const RsGxsId& destination, const GRouterServiceId& client_id, const uint8_t *data, uint32_t data_size, const RsGxsId& signing_id, GRouterMsgPropagationId& id) ; // Cancels a given sending order. If called too late, the message might already have left. But this will remove the item from the // re-try list. diff --git a/libretroshare/src/gxs/gxssecurity.cc b/libretroshare/src/gxs/gxssecurity.cc index a74879e15..818c1d1c9 100644 --- a/libretroshare/src/gxs/gxssecurity.cc +++ b/libretroshare/src/gxs/gxssecurity.cc @@ -385,7 +385,13 @@ bool GxsSecurity::encrypt(uint8_t *& out, int & outlen, const uint8_t *in, int i if(!EVP_SealInit(&ctx, EVP_aes_128_cbc(), &ek, &eklen, iv, &public_key, 1)) return false; // now assign memory to out accounting for data, and cipher block size, key length, and key length val - out = new uint8_t[inlen + cipher_block_size + size_net_ekl + eklen + EVP_MAX_IV_LENGTH]; + out = (uint8_t*)malloc(inlen + cipher_block_size + size_net_ekl + eklen + EVP_MAX_IV_LENGTH); + + if(out == NULL) + { + std::cerr << "gxssecurity::encrypt(): cnnot allocate memory of size " << inlen + cipher_block_size + size_net_ekl + eklen + EVP_MAX_IV_LENGTH << " to encrypt data." << std::endl; + return false ; + } net_ekl = htonl(eklen); memcpy((unsigned char*)out + out_offset, &net_ekl, size_net_ekl); @@ -400,7 +406,7 @@ bool GxsSecurity::encrypt(uint8_t *& out, int & outlen, const uint8_t *in, int i // now encrypt actual data if(!EVP_SealUpdate(&ctx, (unsigned char*) out + out_offset, &out_currOffset, (unsigned char*) in, inlen)) { - delete[] out ; + free(out) ; out = NULL ; return false; } @@ -411,7 +417,7 @@ bool GxsSecurity::encrypt(uint8_t *& out, int & outlen, const uint8_t *in, int i // add padding if(!EVP_SealFinal(&ctx, (unsigned char*) out + out_offset, &out_currOffset)) { - delete[] out ; + free(out) ; out = NULL ; return false; } @@ -422,7 +428,7 @@ bool GxsSecurity::encrypt(uint8_t *& out, int & outlen, const uint8_t *in, int i // make sure offset has not gone passed valid memory bounds if(out_offset > max_outlen) { - delete[] out ; + free(out) ; out = NULL ; return false; } @@ -498,11 +504,17 @@ bool GxsSecurity::decrypt(uint8_t *& out, int & outlen, const uint8_t *in, int i std::cerr << "Severe error in " << __PRETTY_FUNCTION__ << ": cannot encrypt. " << std::endl; return false ; } - out = new uint8_t[inlen - in_offset]; + out = (uint8_t*)malloc(inlen - in_offset); + + if(out == NULL) + { + std::cerr << "gxssecurity::decrypt(): cannot allocate memory of size " << inlen - in_offset << " to decrypt data." << std::endl; + return false; + } if(!EVP_OpenUpdate(&ctx, (unsigned char*) out, &out_currOffset, (unsigned char*)in + in_offset, inlen - in_offset)) { - delete[] out ; + free(out) ; out = NULL ; return false; } @@ -511,7 +523,7 @@ bool GxsSecurity::decrypt(uint8_t *& out, int & outlen, const uint8_t *in, int i if(!EVP_OpenFinal(&ctx, (unsigned char*)out + out_currOffset, &out_currOffset)) { - delete[] out ; + free(out) ; out = NULL ; return false; } diff --git a/libretroshare/src/retroshare/rsgrouter.h b/libretroshare/src/retroshare/rsgrouter.h index 6b10c14cb..142bd9eda 100644 --- a/libretroshare/src/retroshare/rsgrouter.h +++ b/libretroshare/src/retroshare/rsgrouter.h @@ -92,7 +92,7 @@ public: // Communication to other services. // //===================================================// - virtual bool sendData(const RsGxsId& destination, const GRouterServiceId& client_id, uint8_t *data, uint32_t data_size, const RsGxsId& signing_id, GRouterMsgPropagationId& id) =0; + virtual bool sendData(const RsGxsId& destination, const GRouterServiceId& client_id, const uint8_t *data, uint32_t data_size, const RsGxsId& signing_id, GRouterMsgPropagationId& id) =0; virtual bool cancel(GRouterMsgPropagationId mid) =0; virtual bool registerKey(const RsGxsId& authentication_id, const GRouterServiceId& client_id,const std::string& description_string)=0 ; diff --git a/libretroshare/src/services/p3msgservice.cc b/libretroshare/src/services/p3msgservice.cc index 77d0d76bf..ed50aa3a1 100644 --- a/libretroshare/src/services/p3msgservice.cc +++ b/libretroshare/src/services/p3msgservice.cc @@ -2263,6 +2263,8 @@ void p3MsgService::sendDistantMsgItem(RsMsgItem *msgitem) GRouterMsgPropagationId grouter_message_id ; mGRouter->sendData(destination_key_id,GROUTER_CLIENT_ID_MESSAGES,msg_serialized_data,msg_serialized_rssize,signing_key_id,grouter_message_id) ; + delete[] msg_serialized_data ; + // now store the grouter id along with the message id, so that we can keep track of received messages { diff --git a/retroshare-gui/src/gui/statistics/GlobalRouterStatistics.cpp b/retroshare-gui/src/gui/statistics/GlobalRouterStatistics.cpp index 8ffc4d872..cf03c35bf 100644 --- a/retroshare-gui/src/gui/statistics/GlobalRouterStatistics.cpp +++ b/retroshare-gui/src/gui/statistics/GlobalRouterStatistics.cpp @@ -218,6 +218,8 @@ void GlobalRouterStatisticsWidget::updateContent() oy += celly ; } } + oy += celly ; + QString prob_string ; painter.setFont(times_f) ; QString Q = tr("Routing matrix (") ; @@ -252,8 +254,6 @@ void GlobalRouterStatisticsWidget::updateContent() oy += celly ; } - oy += celly ; - oy += celly ;