diff options
author | Daniel Stenberg <daniel@haxx.se> | 2004-12-16 22:20:33 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2004-12-16 22:20:33 +0000 |
commit | 6e1e9caa32da099569bb95e64faf0b5f3cf103b5 (patch) | |
tree | a37c6ef7720ee038faf86dec136d12cf11382725 | |
parent | f71725de6e0b4890f85f9f623684a876b9fdfdd8 (diff) |
Based on Gisle Vanem's patch: make sure the directory re-use works even when
a URL-encoded path is used.
-rw-r--r-- | lib/ftp.c | 26 |
1 files changed, 19 insertions, 7 deletions
@@ -765,23 +765,29 @@ CURLcode Curl_ftp_done(struct connectdata *conn, CURLcode status) bool was_ctl_valid = ftp->ctl_valid; size_t flen; size_t dlen; + char *path; /* now store a copy of the directory we are in */ if(ftp->prevpath) free(ftp->prevpath); - flen = ftp->file?strlen(ftp->file):0; - dlen = conn->path?strlen(conn->path)-flen:0; + path = curl_unescape(conn->path, 0); /* get the "raw" path */ + if(!path) + CURLE_OUT_OF_MEMORY; + + flen = ftp->file?strlen(ftp->file):0; /* file is "raw" already */ + dlen = strlen(path)-flen; if(dlen) { ftp->prevpath = malloc(dlen + 1); if(!ftp->prevpath) return CURLE_OUT_OF_MEMORY; - memcpy(ftp->prevpath, conn->path, dlen); + memcpy(ftp->prevpath, path, dlen); ftp->prevpath[dlen]=0; /* terminate */ infof(data, "Remembering we are in dir %s\n", ftp->prevpath); } else ftp->prevpath = NULL; /* no path */ + free(path); /* free the dir tree and file parts */ freedirs(ftp); @@ -2771,14 +2777,20 @@ CURLcode ftp_parse_url_path(struct connectdata *conn) ftp->cwddone = FALSE; /* default to not done */ - dlen = conn->path?strlen(conn->path):0; - if(dlen && ftp->prevpath) { - dlen -= ftp->file?strlen(ftp->file):0; + if(ftp->prevpath) { + /* prevpath is "raw" so we convert the input path before we compare the + strings */ + char *path = curl_unescape(conn->path, 0); + if(!path) + return CURLE_OUT_OF_MEMORY; + + dlen = strlen(path) - (ftp->file?strlen(ftp->file):0); if((dlen == strlen(ftp->prevpath)) && - curl_strnequal(conn->path, ftp->prevpath, dlen)) { + curl_strnequal(path, ftp->prevpath, dlen)) { infof(data, "Request has same path as previous transfer\n"); ftp->cwddone = TRUE; } + free(path); } return retcode; |