From c6feef6c869c1b51d585e292296ebb3dfcfd2c9d Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 23 Jan 2019 20:28:09 -0800 Subject: [PATCH] GUACAMOLE-637: Clarify purpose of initial empty path component. Fix normalization logic to ensure that empty component is always present. --- src/protocols/rdp/rdp_fs.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/protocols/rdp/rdp_fs.c b/src/protocols/rdp/rdp_fs.c index 3319e1db..6b9bf044 100644 --- a/src/protocols/rdp/rdp_fs.c +++ b/src/protocols/rdp/rdp_fs.c @@ -608,11 +608,15 @@ const char* guac_rdp_fs_read_dir(guac_rdp_fs* fs, int file_id) { int guac_rdp_fs_normalize_path(const char* path, char* abs_path) { int i; - int path_depth = 1; - char path_component_data[GUAC_RDP_FS_MAX_PATH]; - const char* path_components[GUAC_RDP_MAX_PATH_DEPTH] = { "" }; - const char* current_path_component_data = &(path_component_data[0]); + char path_component_data[GUAC_RDP_FS_MAX_PATH]; + const char* current_path_component_data = &(path_component_data[0]); + + /* Always include a blank path component at the beginning, such that the + * eventual call to guac_strljoin() will produce an absolute path (leading + * backslash) */ + int path_depth = 1; + const char* path_components[GUAC_RDP_MAX_PATH_DEPTH] = { "" }; /* If original path is not absolute, normalization fails */ if (path[0] != '\\' && path[0] != '/') @@ -641,7 +645,7 @@ int guac_rdp_fs_normalize_path(const char* path, char* abs_path) { /* If component refers to parent, just move up in depth */ if (strcmp(current_path_component_data, "..") == 0) { - if (path_depth > 0) + if (path_depth > 1) path_depth--; }