- Fixed crash because of a memory overwrite

The static arrays in RsDiscSpace were to small for RS_PGP_DIRECTORY (0x0003)
  Added new constant RS_DIRECTORY_COUNT
- Added missing fclose to PGPHandler::encryptTextToFile
  Used ops_teardown_file_write instead of ops_writer_close and ops_create_info_delete
  Windows cannot move a file when it is still open

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6542 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2013-07-26 23:12:09 +00:00
parent b84930b157
commit e95725ea2c
4 changed files with 16 additions and 14 deletions

View File

@ -1059,11 +1059,6 @@ bool PGPHandler::encryptTextToFile(const PGPIdType& key_id,const std::string& te
{ {
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures. RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
std::string outfile_tmp = outfile + ".tmp" ;
ops_create_info_t *info;
int fd = ops_setup_file_write(&info, outfile_tmp.c_str(), ops_true);
const ops_keydata_t *public_key = locked_getPublicKey(key_id,true) ; const ops_keydata_t *public_key = locked_getPublicKey(key_id,true) ;
if(public_key == NULL) if(public_key == NULL)
@ -1078,15 +1073,20 @@ bool PGPHandler::encryptTextToFile(const PGPIdType& key_id,const std::string& te
return false ; return false ;
} }
std::string outfile_tmp = outfile + ".tmp" ;
ops_create_info_t *info;
int fd = ops_setup_file_write(&info, outfile_tmp.c_str(), ops_true);
if (fd < 0) if (fd < 0)
{ {
std::cerr << "PGPHandler::encryptTextToFile(): ERROR: Cannot write to " << outfile_tmp << std::endl; std::cerr << "PGPHandler::encryptTextToFile(): ERROR: Cannot write to " << outfile_tmp << std::endl;
return false ; return false ;
} }
ops_encrypt_stream(info, public_key, NULL, ops_false, ops_true); ops_encrypt_stream(info, public_key, NULL, ops_false, ops_true);
ops_write(text.c_str(), text.length(), info); ops_write(text.c_str(), text.length(), info);
ops_writer_close(info); ops_teardown_file_write(info, fd);
ops_create_info_delete(info);
if(!RsDirUtil::renameFile(outfile_tmp,outfile)) if(!RsDirUtil::renameFile(outfile_tmp,outfile))
{ {

View File

@ -58,6 +58,7 @@ const uint32_t RS_PARTIALS_DIRECTORY = 0x0000 ;
const uint32_t RS_DOWNLOAD_DIRECTORY = 0x0001 ; const uint32_t RS_DOWNLOAD_DIRECTORY = 0x0001 ;
const uint32_t RS_CONFIG_DIRECTORY = 0x0002 ; const uint32_t RS_CONFIG_DIRECTORY = 0x0002 ;
const uint32_t RS_PGP_DIRECTORY = 0x0003 ; const uint32_t RS_PGP_DIRECTORY = 0x0003 ;
const uint32_t RS_DIRECTORY_COUNT = 0x0004 ;
class Sha1CheckSum class Sha1CheckSum
{ {

View File

@ -40,10 +40,10 @@
* #define DEBUG_RSDISCSPACE * #define DEBUG_RSDISCSPACE
*/ */
time_t RsDiscSpace::_last_check[3] = { 0,0,0 } ; time_t RsDiscSpace::_last_check[RS_DIRECTORY_COUNT] = { 0,0,0,0 } ;
uint32_t RsDiscSpace::_size_limit_mb = 100 ; uint32_t RsDiscSpace::_size_limit_mb = 100 ;
uint32_t RsDiscSpace::_current_size[3] = { 10000,10000,10000 } ; uint32_t RsDiscSpace::_current_size[RS_DIRECTORY_COUNT] = { 10000,10000,10000,10000 } ;
bool RsDiscSpace::_last_res[3] = { true,true,true }; bool RsDiscSpace::_last_res[RS_DIRECTORY_COUNT] = { true,true,true,true };
RsMutex RsDiscSpace::_mtx("RsDiscSpace") ; RsMutex RsDiscSpace::_mtx("RsDiscSpace") ;
std::string RsDiscSpace::_partials_path = "" ; std::string RsDiscSpace::_partials_path = "" ;
std::string RsDiscSpace::_download_path = "" ; std::string RsDiscSpace::_download_path = "" ;

View File

@ -28,6 +28,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <util/rsthreads.h> #include <util/rsthreads.h>
#include <retroshare/rstypes.h>
class RsDiscSpace class RsDiscSpace
{ {
@ -53,10 +54,10 @@ class RsDiscSpace
static RsMutex _mtx ; static RsMutex _mtx ;
static time_t _last_check[3] ; static time_t _last_check[RS_DIRECTORY_COUNT] ;
static uint32_t _size_limit_mb ; static uint32_t _size_limit_mb ;
static uint32_t _current_size[3] ; static uint32_t _current_size[RS_DIRECTORY_COUNT] ;
static bool _last_res[3] ; static bool _last_res[RS_DIRECTORY_COUNT] ;
static std::string _partials_path ; static std::string _partials_path ;
static std::string _download_path ; static std::string _download_path ;