Skip to content

Commit

Permalink
Do not allow "." hostname when converting to UNC path
Browse files Browse the repository at this point in the history
  • Loading branch information
rmisev committed Nov 22, 2023
1 parent 1f95bfb commit bb9763c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/upa/url.h
Original file line number Diff line number Diff line change
Expand Up @@ -3125,6 +3125,9 @@ inline std::string path_from_file_url(const url& file_url, file_path_format form
} else {
// format == file_path_format::windows
if (is_host) {
// UNC path cannot have "." hostname, because "\\.\" means DOS devices namespace
if (hostname == ".")
throw url_error(validation_errc::file_url_unsupported_host, "UNC path cannot have \".\" hostname");
// UNC path
path.append("\\\\");
path.append(hostname);
Expand Down
1 change: 1 addition & 0 deletions include/upa/url_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ enum class validation_errc {
// path_from_file_url errors
not_file_url, ///< Not a file URL
file_url_cannot_have_host, ///< POSIX path cannot have host
file_url_unsupported_host, ///< UNC path cannot have "." hostname
file_url_invalid_unc, ///< Invalid UNC path in file URL
file_url_not_windows_path, ///< Not a Windows path in file URL
};
Expand Down
2 changes: 2 additions & 0 deletions test/test-url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,8 @@ TEST_CASE("path_from_file_url") {
CHECK_THROWS_AS(path_from_file_url("file://host/", upa::file_path_format::windows), upa::url_error);
CHECK_THROWS_AS(path_from_file_url("file:////host/", upa::file_path_format::windows), upa::url_error);
CHECK_THROWS_AS(path_from_file_url("file://///host/", upa::file_path_format::windows), upa::url_error);
// Unsupported "." hostname
CHECK_THROWS_AS(path_from_file_url("file://./name", upa::file_path_format::windows), upa::url_error);
}
SUBCASE("Native path") {
#ifdef _WIN32
Expand Down

0 comments on commit bb9763c

Please sign in to comment.