FTP: URL decode path for dir listing in nocwd mode

Reported-by: Zenju on github

Test 244 added to verify
Fixes #1974
Closes #1976
This commit is contained in:
Daniel Stenberg 2017-10-10 12:02:11 +02:00
parent 00fb811e2b
commit ecf21c551f
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
3 changed files with 64 additions and 13 deletions

View file

@ -1457,25 +1457,22 @@ static CURLcode ftp_state_list(struct connectdata *conn)
then just do LIST (in that case: nothing to do here)
*/
char *cmd, *lstArg, *slashPos;
const char *inpath = data->state.path;
lstArg = NULL;
if((data->set.ftp_filemethod == FTPFILE_NOCWD) &&
data->state.path &&
data->state.path[0] &&
strchr(data->state.path, '/')) {
lstArg = strdup(data->state.path);
if(!lstArg)
return CURLE_OUT_OF_MEMORY;
inpath && inpath[0] && strchr(inpath, '/')) {
size_t n = strlen(inpath);
/* Check if path does not end with /, as then we cut off the file part */
if(lstArg[strlen(lstArg) - 1] != '/') {
if(inpath[n - 1] != '/') {
/* chop off the file part if format is dir/dir/file */
slashPos = strrchr(lstArg, '/');
if(slashPos)
*(slashPos + 1) = '\0';
slashPos = strrchr(inpath, '/');
n = slashPos - inpath;
}
result = Curl_urldecode(data, inpath, n, &lstArg, NULL, FALSE);
if(result)
return result;
}
cmd = aprintf("%s%s%s",