From 00f838e3b4f844166f208a01f0b9f39f988198cd Mon Sep 17 00:00:00 2001 From: Wirlaburla Date: Wed, 1 Jan 2025 12:46:58 -0600 Subject: [PATCH] fix broken memory when assigning fd.path variable --- src/plugins/filer_local/filer_local.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/plugins/filer_local/filer_local.cpp b/src/plugins/filer_local/filer_local.cpp index 4d661ec..0716430 100644 --- a/src/plugins/filer_local/filer_local.cpp +++ b/src/plugins/filer_local/filer_local.cpp @@ -27,7 +27,7 @@ public: try { // Always convert to absolute path fs::path new_root = fs::absolute(fs::weakly_canonical(_root)); - fd.path = new_root.string().c_str(); + fd.path = strdup(new_root.c_str()); // Create directory if it doesn't exist if (!fs::exists(new_root)) { @@ -55,7 +55,7 @@ public: try { // Always convert to absolute path fs::path new_cwd = fs::weakly_canonical(_cwd); - fd.path = new_cwd.string().c_str(); + fd.path = strdup(new_cwd.c_str()); // Create directory if it doesn't exist if (!fs::exists(root / new_cwd)) { @@ -131,7 +131,7 @@ public: } if (dir.empty() || dir == ".") { - fd.path = requested_path.c_str(); + fd.path = strdup(requested_path.c_str()); return fd; } @@ -155,7 +155,7 @@ public: // Update current working directory relative to root cwd = "/" + rel_path.string(); - fd.path = requested_path.string().c_str(); + fd.path = strdup(requested_path.c_str()); } catch (const fs::filesystem_error& ex) { logger->print(LOGLEVEL_ERROR, "Path fallback: %s", ex.what()); @@ -173,7 +173,7 @@ public: return fd; } - fd.path = resolved.string().c_str(); + fd.path = strdup(resolved.c_str()); if (fs::exists(resolved)) { fd.error = file_error{FilerStatusCodes::FileExists, "Directory Already Exists"}; @@ -196,7 +196,7 @@ public: fd.error = file_error{FilerStatusCodes::NoPermission, "Invalid Permissions"}; return fd; } - fd.path = resolved.string().c_str(); + fd.path = strdup(resolved.c_str()); if (!fs::exists(resolved)) { fd.error = file_error{FilerStatusCodes::NotFound, "File Not Found"}; @@ -229,7 +229,7 @@ public: fd.error = file_error{FilerStatusCodes::NoPermission, "Invalid Permissions"}; return fd; } - fd.path = resolved.c_str(); + fd.path = strdup(resolved.c_str()); std::error_code err; if (!fs::remove(resolved, err)) { @@ -259,7 +259,7 @@ public: fd.error = file_error{FilerStatusCodes::NoPermission, "Invalid Permissions"}; return fd; } - fd.path = resolved.string().c_str(); + fd.path = strdup(resolved.c_str()); if (!fs::exists(resolved)) { fd.error = file_error{FilerStatusCodes::NotFound, "File Not Found"}; @@ -296,7 +296,7 @@ public: fd.error = file_error{FilerStatusCodes::NoPermission, "Invalid Permissions"}; return fd; } - fd.path = resolved.string().c_str(); + fd.path = strdup(resolved.c_str()); std::ios_base::openmode omode = std::ios::out|std::ios::binary; if (append) omode |= std::ios::app; @@ -338,8 +338,8 @@ public: // Perform the rename operation std::filesystem::rename(src_path, dst_path); + fd.path = strdup(dst_path.c_str()); fd.error = {0, "OK"}; - } catch (const std::filesystem::filesystem_error& e) { fd.error = {FilerStatusCodes::AccessDenied, e.what()}; } @@ -355,7 +355,7 @@ public: fd.error = file_error{FilerStatusCodes::NoPermission, "Invalid Permissions"}; return fd; } - fd.path = resolved.string().c_str(); + fd.path = strdup(resolved.c_str()); if (!fs::exists(resolved)) { fd.error = file_error{FilerStatusCodes::NotFound, "File Not Found"};