Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: potential dangling pointers and buffer overflow #366

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions daemon/extension/Extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ namespace Extension
}
else if (const double* val = std::get_if<double>(&option.value))
{
Xml::AddNewNode(optionsNode, "Value", "double", std::to_string(*val).c_str());
std::string valStr = std::to_string(*val);
Xml::AddNewNode(optionsNode, "Value", "double", valStr.c_str());
}

xmlNodePtr selectNode = xmlNewNode(nullptr, BAD_CAST "Select");
Expand All @@ -414,7 +415,8 @@ namespace Extension
}
else if (const double* val = std::get_if<double>(&selectOption))
{
Xml::AddNewNode(selectNode, "Value", "double", std::to_string(*val).c_str());
std::string valStr = std::to_string(*val);
Xml::AddNewNode(selectNode, "Value", "double", valStr.c_str());
}
}

Expand Down
6 changes: 3 additions & 3 deletions daemon/util/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ void FileSystem::NormalizePathSeparators(char* path)
}
}

std::optional<std::string> FileSystem::GetFileRealPath(std::string_view path)
std::optional<std::string> FileSystem::GetFileRealPath(const std::string& path)
{
#ifdef WIN32
char buffer[MAX_PATH];
DWORD len = GetFullPathName(path.data(), MAX_PATH, buffer, nullptr);
DWORD len = GetFullPathName(path.c_str(), MAX_PATH, buffer, nullptr);
if (len != 0)
{
return std::optional{ buffer };
}
#else
if (char* realPath = realpath(path.data(), nullptr))
if (char* realPath = realpath(path.c_str(), nullptr))
{
std::string res = realPath;
free(realPath);
Expand Down
2 changes: 1 addition & 1 deletion daemon/util/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class FileSystem
static char* BaseFileName(const char* filename);
static bool SameFilename(const char* filename1, const char* filename2);
static void NormalizePathSeparators(char* path);
static std::optional<std::string> GetFileRealPath(std::string_view path);
static std::optional<std::string> GetFileRealPath(const std::string& path);
static bool LoadFileIntoBuffer(const char* filename, CharBuffer& buffer, bool addTrailingNull);
static bool SaveBufferIntoFile(const char* filename, const char* buffer, int bufLen);
static bool AllocateFile(const char* filename, int64 size, bool sparse, CString& errmsg);
Expand Down