check by using fopen if f is valid, because started in /usr/local/bin without admin don't allow fopen in same dir as binary and leads to Segmentation fault error and crash

This commit is contained in:
einhornimmond - MarkX 2020-09-07 08:49:36 +02:00
parent 939e942ba8
commit 53d1309517
4 changed files with 24 additions and 14 deletions

View File

@ -64,8 +64,10 @@ int Mnemonic::init(void(*fill_words_func)(unsigned char*), unsigned int original
uncompressed_file_name += std::to_string(original_size);
uncompressed_file_name += ".txt";
FILE* f = fopen(uncompressed_file_name.data(), "w");
fwrite(uncompressed_buffer, sizeof(char), original_size, f);
fclose(f);
if (f) {
fwrite(uncompressed_buffer, sizeof(char), original_size, f);
fclose(f);
}
unsigned short cursor = 0;
u32 word_begin = 0, word_end = 0;
@ -335,9 +337,11 @@ void Mnemonic::printToFile(const char* filename)
{
std::shared_lock<std::shared_mutex> _lock(mWorkingMutex);
FILE* f = fopen(filename, "wt");
auto words = getCompleteWordListSorted();
fwrite(words.data(), 1, words.size(), f);
fclose(f);
if (f) {
auto words = getCompleteWordListSorted();
fwrite(words.data(), 1, words.size(), f);
fclose(f);
}
}
Poco::JSON::Array Mnemonic::getSortedWordList()

View File

@ -73,9 +73,11 @@ Poco::Dynamic::Var JsonRequestHandler::parseJsonWithErrorPrintFile(std::istream&
std::string dateTimeString = Poco::DateTimeFormatter::format(Poco::DateTime(), "%d_%m_%yT%H_%M_%S");
std::string filename = dateTimeString + "_response.html";
FILE* f = fopen(filename.data(), "wt");
std::string responseString = responseStringStream.str();
fwrite(responseString.data(), 1, responseString.size(), f);
fclose(f);
if (f) {
std::string responseString = responseStringStream.str();
fwrite(responseString.data(), 1, responseString.size(), f);
fclose(f);
}
return Poco::Dynamic::Var();
}
return Poco::Dynamic::Var();

View File

@ -70,9 +70,11 @@ JsonRequestReturn JsonRequest::request(const char* methodName, const Poco::Net::
fileName += ".html";
FILE* f = fopen(fileName.data(), "wt");
std::string responseString = responseStringStream.str();
fwrite(responseString.data(), 1, responseString.size(), f);
fclose(f);
if (f) {
std::string responseString = responseStringStream.str();
fwrite(responseString.data(), 1, responseString.size(), f);
fclose(f);
}
// */
sendErrorsAsEmail(responseStringStream.str());
return JSON_REQUEST_RETURN_PARSE_ERROR;

View File

@ -220,9 +220,11 @@ int SigningTransaction::run() {
addError(new ParamError("SigningTransaction", "error parsing request answer", ex.displayText().data()));
FILE* f = fopen("response.html", "wt");
std::string responseString = responseStringStream.str();
fwrite(responseString.data(), 1, responseString.size(), f);
fclose(f);
if (f) {
std::string responseString = responseStringStream.str();
fwrite(responseString.data(), 1, responseString.size(), f);
fclose(f);
}
// */
sendErrorsAsEmail(responseStringStream.str());
return -9;