Skip to content

FTP Bug: wrong dir listing because libcurl remembers wrong CWD #1782

@PeterLamare2

Description

@PeterLamare2

I think this is caused by the changes in:
#1718

Steps to reproduce:
When the first easy handle uses CURLFTPMETHOD_MULTICWD and accesses some path /subfolder, libcurl stores this under ftpc->prevpath.

The easy handle is then reused, but this time using CURLFTPMETHOD_NOCWD, also passing /subfolder as CURLOPT_URL.
Now in ftp.c:: ftp_parse_url_path, there is still this code which does not consider CURLFTPMETHOD

  ftpc->cwddone = FALSE; /* default to not done */

  if(ftpc->prevpath) {
    /* prevpath is "raw" so we convert the input path before we compare the
       strings */
    size_t dlen;
    char *path;
    CURLcode result =
      Curl_urldecode(conn->data, data->state.path, 0, &path, &dlen, FALSE);
    if(result) {
      freedirs(ftpc);
      return result;
    }

    dlen -= ftpc->file?strlen(ftpc->file):0;
    if((dlen == strlen(ftpc->prevpath)) &&
       !strncmp(path, ftpc->prevpath, dlen)) {
      infof(data, "Request has same path as previous transfer\n");
      ftpc->cwddone = TRUE;
    }
    free(path);
  }

Consequence: ftpc->cwddone = TRUE; will be set, which is incorrect for CURLFTPMETHOD_NOCWD, which is supposed to operate on the ftp entry path.

As a result, the CURLFTPMETHOD_NOCWD + "MLSD subfolder" will not find any results, because the working dir is alreay at /subfolder! (consider CURLOPT_CUSTOMREQUEST MLSD)

-Lama

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions