aboutsummaryrefslogtreecommitdiff
path: root/lib/ftp.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2013-04-12 15:29:28 +0200
committerDaniel Stenberg <daniel@haxx.se>2013-04-12 22:43:13 +0200
commit61d259f95045c2ec029d4234af80b00d91fec080 (patch)
tree5aa64b7102d3f9acdde7890adfe8202f7ba03037 /lib/ftp.c
parentc01735865fcf0f35bb845762a9791c32ce9c0c4d (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/ftp.c')
-rw-r--r--lib/ftp.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/ftp.c b/lib/ftp.c
index dce23de75..5308b2fa2 100644
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -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;
}