From ff4c538a9f669dd5c3122decfa34274644a4c220 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 24 Apr 2026 13:50:38 +0000 Subject: [PATCH] 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> --- include/xrpl/beast/utility/temp_dir.h | 3 ++- src/libxrpl/nodestore/backend/NuDBFactory.cpp | 1 + src/test/app/GRPCServerTLS_test.cpp | 11 ++++++----- src/xrpld/app/main/GRPCServer.cpp | 1 + src/xrpld/app/misc/SHAMapStoreImp.cpp | 8 +++----- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/include/xrpl/beast/utility/temp_dir.h b/include/xrpl/beast/utility/temp_dir.h index 71ceeb5d48..f479264a58 100644 --- a/include/xrpl/beast/utility/temp_dir.h +++ b/include/xrpl/beast/utility/temp_dir.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include @@ -32,7 +33,7 @@ public: do { std::ostringstream oss; - oss << std::hex << rd() << rd(); + oss << std::hex << std::setfill('0') << std::setw(8) << rd() << std::setw(8) << rd(); path_ = dir / oss.str(); } while (std::filesystem::exists(path_)); std::filesystem::create_directory(path_); diff --git a/src/libxrpl/nodestore/backend/NuDBFactory.cpp b/src/libxrpl/nodestore/backend/NuDBFactory.cpp index b86f73af50..c9a5e23e77 100644 --- a/src/libxrpl/nodestore/backend/NuDBFactory.cpp +++ b/src/libxrpl/nodestore/backend/NuDBFactory.cpp @@ -17,6 +17,7 @@ #include +#include #include #include diff --git a/src/test/app/GRPCServerTLS_test.cpp b/src/test/app/GRPCServerTLS_test.cpp index cdfd6c75a3..a8f50547cd 100644 --- a/src/test/app/GRPCServerTLS_test.cpp +++ b/src/test/app/GRPCServerTLS_test.cpp @@ -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); diff --git a/src/xrpld/app/main/GRPCServer.cpp b/src/xrpld/app/main/GRPCServer.cpp index e8b2b2ddfb..b62192f66e 100644 --- a/src/xrpld/app/main/GRPCServer.cpp +++ b/src/xrpld/app/main/GRPCServer.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include diff --git a/src/xrpld/app/misc/SHAMapStoreImp.cpp b/src/xrpld/app/misc/SHAMapStoreImp.cpp index b002178ae9..74a475d92e 100644 --- a/src/xrpld/app/misc/SHAMapStoreImp.cpp +++ b/src/xrpld/app/misc/SHAMapStoreImp.cpp @@ -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());