Skip to content

Commit 088e98e

Browse files
[Fix] Windows Server
1 parent 8e9bf5e commit 088e98e

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

func/server/server.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -501,20 +501,24 @@ int start_server(const std::string& root_path, int port) {
501501
std::string combined_str = combined.string();
502502
std::string root_str = real_root.string();
503503

504+
// On Windows, preferred_separator is wchar_t, but we are using std::string (char).
505+
// We need to cast it to char for string operations.
506+
const char path_sep = static_cast<char>(fs::path::preferred_separator);
507+
504508
// Ensure root_str ends with separator for accurate prefix matching
505-
if (!root_str.empty() && root_str.back() != fs::path::preferred_separator) {
506-
root_str += fs::path::preferred_separator;
509+
if (!root_str.empty() && root_str.back() != path_sep) {
510+
root_str += path_sep;
507511
}
508-
if (!combined_str.empty() && combined_str.back() != fs::path::preferred_separator
512+
if (!combined_str.empty() && combined_str.back() != path_sep
509513
&& fs::is_directory(combined)) {
510-
combined_str += fs::path::preferred_separator;
514+
combined_str += path_sep;
511515
}
512516

513517
// Check if combined path starts with root path
514518
if (combined_str.size() < root_str.size() ||
515519
combined_str.substr(0, root_str.size()) != root_str) {
516520
// Allow exact match with root
517-
if (combined_str + fs::path::preferred_separator != root_str) {
521+
if (combined_str + path_sep != root_str) {
518522
return ""; // Path traversal detected
519523
}
520524
}

0 commit comments

Comments
 (0)