Address code review: improve random path generation and fix includes

Agent-Logs-Url: https://github.com/XRPLF/rippled/sessions/ec2fa57d-2d9c-4388-b4e1-90a40f55b5e8

Co-authored-by: mvadari <8029314+mvadari@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-04-24 13:50:38 +00:00
committed by GitHub
parent 9fe94c47c3
commit ff4c538a9f
5 changed files with 13 additions and 11 deletions

View File

@@ -17,6 +17,7 @@
#include <filesystem>
#include <system_error>
#include <boost/system/detail/errc.hpp>
#include <nudb/context.hpp>

View File

@@ -257,12 +257,13 @@ public:
TemporaryTLSCertificates()
{
auto tmpDir = std::filesystem::temp_directory_path();
// Generate 8 random hex characters to create a unique directory name
std::random_device rd;
std::ostringstream oss;
oss << kCERTS_DIR_PREFIX << std::hex << std::setfill('0') << std::setw(8)
<< (rd() & 0xFFFFFFFF);
tempDir_ = tmpDir / oss.str();
do
{
std::ostringstream oss;
oss << kCERTS_DIR_PREFIX << std::hex << std::setfill('0') << std::setw(8) << rd();
tempDir_ = tmpDir / oss.str();
} while (std::filesystem::exists(tempDir_));
std::filesystem::create_directories(tempDir_);
writeFile(tempDir_ / kCA_CERT_FILENAME, kCA_CERT_CONTENT);

View File

@@ -47,6 +47,7 @@
#include <optional>
#include <sstream>
#include <stdexcept>
#include <system_error>
#include <string>
#include <utility>
#include <vector>

View File

@@ -472,13 +472,11 @@ SHAMapStoreImp::makeBackendRotating(std::string path)
}
else
{
std::filesystem::path p = get(section, "path");
p /= dbPrefix_;
// Generate 4 random hex characters to create a unique path
std::filesystem::path const p = get(section, "path");
std::random_device rd;
std::ostringstream oss;
oss << std::hex << std::setfill('0') << std::setw(4) << (rd() & 0xFFFF);
newPath = p.string() + "." + oss.str();
oss << std::hex << std::setfill('0') << std::setw(8) << rd();
newPath = (p / dbPrefix_).string() + "." + oss.str();
}
section.set("path", newPath.string());