Skip to content

Commit

Permalink
Switch to a more secure method for generating random file names.
Browse files Browse the repository at this point in the history
  • Loading branch information
AiraYumi committed Nov 16, 2024
1 parent 191ba93 commit d6982a2
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 d6982a2

Please sign in to comment.