Skip to content

Commit

Permalink
Merge pull request #12 from AiraYumi/use_secure_functions
Browse files Browse the repository at this point in the history
Switch to a more secure method for generating random file names.
  • Loading branch information
bennettgoble authored Jan 16, 2025
2 parents 20463b5 + d6982a2 commit 5e7d7e4
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/dae/daeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#ifndef NO_BOOST
#include <boost/filesystem.hpp> // THIS WAS NOT COMMENTED.
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#endif

#include <cstdio> // for tmpnam
Expand Down Expand Up @@ -169,8 +171,13 @@ static string tmpDir = string(getenv("TMPDIR"));
string cdom::getRandomFileName() {
std::string randomSegment;
// have to createa a buffer in order to make it multi-thread safe
#ifdef NO_BOOST
std::string tmpbuffer; tmpbuffer.resize(L_tmpnam*2+1);
std::string tmp(tmpnam(&tmpbuffer[0]));
#else
boost::uuids::uuid uuid = boost::uuids::random_generator()();
std::string tmp(boost::uuids::to_string(uuid));
#endif
#ifdef WIN32
randomSegment = tmp.substr(tmp.find_last_of('\\')+1);
#elif defined(__linux__) || defined(__linux)
Expand Down

0 comments on commit 5e7d7e4

Please sign in to comment.