diff options
author | Daniel Stenberg <daniel@haxx.se> | 2013-04-12 15:29:28 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2013-04-12 22:43:13 +0200 |
commit | 61d259f95045c2ec029d4234af80b00d91fec080 (patch) | |
tree | 5aa64b7102d3f9acdde7890adfe8202f7ba03037 /lib | |
parent | c01735865fcf0f35bb845762a9791c32ce9c0c4d (diff) |
FTP: access files in root dir correctly
Accessing a file with an absolute path in the root dir but with no
directory specified was not handled correctly. This fix comes with four
new test cases that verify it.
Bug: http://curl.haxx.se/mail/lib-2013-04/0142.html
Reported by: Sam Deane
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ftp.c | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -4316,13 +4316,17 @@ CURLcode ftp_parse_url_path(struct connectdata *conn) } slash_pos=strrchr(cur_pos, '/'); if(slash_pos || !*cur_pos) { + size_t dirlen = slash_pos-cur_pos; + ftpc->dirs = calloc(1, sizeof(ftpc->dirs[0])); if(!ftpc->dirs) return CURLE_OUT_OF_MEMORY; + if(!dirlen) + dirlen++; + ftpc->dirs[0] = curl_easy_unescape(conn->data, slash_pos ? cur_pos : "/", - slash_pos ? - curlx_sztosi(slash_pos-cur_pos) : 1, + slash_pos ? curlx_sztosi(dirlen) : 1, NULL); if(!ftpc->dirs[0]) { freedirs(ftpc); @@ -4377,6 +4381,15 @@ CURLcode ftp_parse_url_path(struct connectdata *conn) } else { cur_pos = slash_pos + 1; /* jump to the rest of the string */ + if(!ftpc->dirdepth) { + /* path starts with a slash, add that as a directory */ + ftpc->dirs[ftpc->dirdepth] = strdup("/"); + if(!ftpc->dirs[ftpc->dirdepth++]) { /* run out of memory ... */ + failf(data, "no memory"); + freedirs(ftpc); + return CURLE_OUT_OF_MEMORY; + } + } continue; } |