Skip to content

Commit

Permalink
fixup! fs: fix crash when path contains %
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Oct 4, 2024
1 parent b82d3c5 commit a706361
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3180,21 +3180,22 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
// Check if src and dest are identical.
if (std::filesystem::equivalent(src_path, dest_path)) {
std::string message = "src and dest cannot be the same %s";
return THROW_ERR_FS_CP_EINVAL(
env, message.c_str(), dest_path.string());
return THROW_ERR_FS_CP_EINVAL(env, message.c_str(), dest_path.string());
}

const bool dest_is_dir =
dest_status.type() == std::filesystem::file_type::directory;

if (src_is_dir && !dest_is_dir) {
std::string message = "Cannot overwrite non-directory %s with directory %s";
std::string message =
"Cannot overwrite non-directory %s with directory %s";
return THROW_ERR_FS_CP_DIR_TO_NON_DIR(
env, message.c_str(), src_path.string(), dest_path.string());
}

if (!src_is_dir && dest_is_dir) {
std::string message = "Cannot overwrite directory %s with non-directory %s";
std::string message =
"Cannot overwrite directory %s with non-directory %s";
return THROW_ERR_FS_CP_NON_DIR_TO_DIR(
env, message.c_str(), dest_path.string(), src_path.string());
}
Expand Down Expand Up @@ -3234,27 +3235,23 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
}

if (src_is_dir && !recursive) {
std::string message = "Recursive option not enabled, cannot copy a directory: %s";
return THROW_ERR_FS_EISDIR(env,
message.c_str(),
src_path_str);
std::string message =
"Recursive option not enabled, cannot copy a directory: %s";
return THROW_ERR_FS_EISDIR(env, message.c_str(), src_path_str);
}

switch (src_status.type()) {
case std::filesystem::file_type::socket: {
std::string message = "Cannot copy a socket file: %s";
return THROW_ERR_FS_CP_SOCKET(
env, message.c_str(), dest_path_str);
return THROW_ERR_FS_CP_SOCKET(env, message.c_str(), dest_path_str);
}
case std::filesystem::file_type::fifo: {
std::string message = "Cannot copy a FIFO pipe: %s";
return THROW_ERR_FS_CP_FIFO_PIPE(
env, message.c_str(), dest_path_str);
return THROW_ERR_FS_CP_FIFO_PIPE(env, message.c_str(), dest_path_str);
}
case std::filesystem::file_type::unknown: {
std::string message = "Cannot copy an unknown file type: %s";
return THROW_ERR_FS_CP_UNKNOWN(
env, message.c_str(), dest_path_str);
return THROW_ERR_FS_CP_UNKNOWN(env, message.c_str(), dest_path_str);
}
default:
break;
Expand Down

0 comments on commit a706361

Please sign in to comment.