Skip to content

Commit 28d1607

Browse files
brycehutchingsrpavlik
authored andcommitted
Fix directory searching
1 parent b0f5622 commit 28d1607

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

src/common/filesystem_utils.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,11 @@ bool FileSysUtilsParsePathList(std::string& path_list, std::vector<std::string>&
230230
}
231231

232232
bool FileSysUtilsFindFilesInPath(const std::string& path, std::vector<std::string>& files) {
233-
// Append "\\*" to file name to list folder contents. This appears to contradict the
234-
// MS documentation and example code, but verified empirically
235-
std::string starred_path = path + DIRECTORY_SYMBOL + "*";
233+
std::string searchPath;
234+
FileSysUtilsCombinePaths(path, "*", searchPath);
236235

237236
WIN32_FIND_DATAW file_data;
238-
HANDLE file_handle = FindFirstFileW(utf8_to_wide(starred_path).c_str(), &file_data);
237+
HANDLE file_handle = FindFirstFileW(utf8_to_wide(searchPath).c_str(), &file_data);
239238
if (file_handle != INVALID_HANDLE_VALUE) {
240239
do {
241240
if (!(file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {

src/common/platform_utils.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,18 +226,20 @@ static inline std::string PlatformUtilsGetEnv(const char* name) {
226226

227227
// GetEnvironmentVariable returns string length, excluding null terminator for "get value" call.
228228
const int length = ::GetEnvironmentVariableW(wname.c_str(), wValueData, (DWORD)wValue.size());
229-
if (!length) {
229+
if (length == 0) {
230230
LogError("GetEnvironmentVariable get value error: " + std::to_string(::GetLastError()));
231231
return {};
232232
}
233233

234+
wValue.resize(length); // Strip the null terminator.
235+
234236
return wide_to_utf8(wValue);
235237
}
236238

237239
static inline std::string PlatformUtilsGetSecureEnv(const char* name) {
238240
// Do not allow high integrity processes to act on data that can be controlled by medium integrity processes.
239241
if (IsHighIntegrityLevel()) {
240-
return nullptr;
242+
return {};
241243
}
242244

243245
// No secure version for Windows so the above integrity check is needed.

0 commit comments

Comments
 (0)