cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: ftp->prevpath bug?

From: Gisle Vanem <giva_at_bgnett.no>
Date: Thu, 16 Dec 2004 22:05:30 +0100

"Daniel Stenberg" wrote:

> Can you set a break-point in Curl_ftp_done() and check the code where prevpath
> is built and see if you can understand how the extra junk gets added to the
> end of the dir name?

Breaking at Curl_ftp_done(), I see conn->path == "www_sider/%2Ehtaccess"
and ftp->file == ".htaccess". 'dlen == 12' when ftp->prevpath gets terminated.

Looks like mixing url-escaped and non-escaped names causes some problems;
no problem with uploading 'htaccess'. So maybe conn->path should be unescaped
too? Don't know if I break anything, but this seems to fix it:

Index: ftp.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/ftp.c,v
retrieving revision 1.285
diff -u -r1.285 ftp.c
--- ftp.c 15 Dec 2004 02:32:04 -0000 1.285
+++ ftp.c 16 Dec 2004 21:04:07 -0000
@@ -770,14 +770,19 @@
   if(ftp->prevpath)
     free(ftp->prevpath);
   {
+ char *path = curl_unescape(conn->path, 0);
     size_t flen = ftp->file?strlen(ftp->file):0;
- size_t dlen = conn->path?strlen(conn->path)-flen:0;
+ size_t dlen = path?strlen(path)-flen:0;
+
+ if(!path)
+ return CURLE_OUT_OF_MEMORY;
     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 */
+ free(path);
       infof(data, "Remembering we are in dir %s\n", ftp->prevpath);
     }
     else

--gv
Received on 2004-12-16