1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

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
This commit is contained in:
Daniel Stenberg 2013-04-12 15:29:28 +02:00
parent c01735865f
commit 61d259f950
7 changed files with 221 additions and 4 deletions

View File

@ -4316,13 +4316,17 @@ CURLcode ftp_parse_url_path(struct connectdata *conn)
} }
slash_pos=strrchr(cur_pos, '/'); slash_pos=strrchr(cur_pos, '/');
if(slash_pos || !*cur_pos) { if(slash_pos || !*cur_pos) {
size_t dirlen = slash_pos-cur_pos;
ftpc->dirs = calloc(1, sizeof(ftpc->dirs[0])); ftpc->dirs = calloc(1, sizeof(ftpc->dirs[0]));
if(!ftpc->dirs) if(!ftpc->dirs)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
if(!dirlen)
dirlen++;
ftpc->dirs[0] = curl_easy_unescape(conn->data, slash_pos ? cur_pos : "/", ftpc->dirs[0] = curl_easy_unescape(conn->data, slash_pos ? cur_pos : "/",
slash_pos ? slash_pos ? curlx_sztosi(dirlen) : 1,
curlx_sztosi(slash_pos-cur_pos) : 1,
NULL); NULL);
if(!ftpc->dirs[0]) { if(!ftpc->dirs[0]) {
freedirs(ftpc); freedirs(ftpc);
@ -4377,6 +4381,15 @@ CURLcode ftp_parse_url_path(struct connectdata *conn)
} }
else { else {
cur_pos = slash_pos + 1; /* jump to the rest of the string */ 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; continue;
} }

View File

@ -90,7 +90,7 @@ test1128 test1129 test1130 test1131 test1132 test1133 \
test1200 test1201 test1202 test1203 test1204 test1205 test1206 test1207 \ test1200 test1201 test1202 test1203 test1204 test1205 test1206 test1207 \
test1208 test1209 test1210 test1211 test1212 test1213 test1214 test1215 \ test1208 test1209 test1210 test1211 test1212 test1213 test1214 test1215 \
test1216 test1217 test1218 \ test1216 test1217 test1218 \
test1220 test1221 test1222 test1223 \ test1220 test1221 test1222 test1223 test1224 test1225 test1226 test1227 \
\ \
test1300 test1301 test1302 test1303 test1304 test1305 test1306 test1307 \ test1300 test1301 test1302 test1303 test1304 test1305 test1306 test1307 \
test1308 test1309 test1310 test1311 test1312 test1313 test1314 test1315 \ test1308 test1309 test1310 test1311 test1312 test1313 test1314 test1315 \

View File

@ -39,7 +39,8 @@ FTP GET with type=A style ASCII URL using %20 codes
USER anonymous USER anonymous
PASS ftp@example.com PASS ftp@example.com
PWD PWD
CWD /path with spaces CWD /
CWD path with spaces
CWD and things2 CWD and things2
EPSV EPSV
TYPE A TYPE A

49
tests/data/test1224 Normal file
View File

@ -0,0 +1,49 @@
<testcase>
<info>
<keywords>
FTP
PASV
RETR
</keywords>
</info>
# Server-side
<reply>
<data>
data
to
see
that FTP
works
so does it?
</data>
</reply>
# Client-side
<client>
<server>
ftp
</server>
<name>
FTP fetch a file from the root directory
</name>
<command>
ftp://%HOSTIP:%FTPPORT//1224
</command>
</client>
# Verify data after the test has been "shot"
<verify>
<protocol>
USER anonymous
PASS ftp@example.com
PWD
CWD /
EPSV
TYPE I
SIZE 1224
RETR 1224
QUIT
</protocol>
</verify>
</testcase>

57
tests/data/test1225 Normal file
View File

@ -0,0 +1,57 @@
<testcase>
<info>
<keywords>
FTP
PASV
RETR
</keywords>
</info>
# Server-side
<reply>
<data>
data
to
see
that FTP
works
so does it?
</data>
</reply>
# Client-side
<client>
<server>
ftp
</server>
<name>
FTP fetch two files using absolute paths
</name>
<command>
ftp://%HOSTIP:%FTPPORT//foo/1225 ftp://%HOSTIP:%FTPPORT//foo/bar/1225
</command>
</client>
# Verify data after the test has been "shot"
<verify>
<protocol>
USER anonymous
PASS ftp@example.com
PWD
CWD /
CWD foo
EPSV
TYPE I
SIZE 1225
RETR 1225
CWD /
CWD /
CWD foo
CWD bar
EPSV
SIZE 1225
RETR 1225
QUIT
</protocol>
</verify>
</testcase>

49
tests/data/test1226 Normal file
View File

@ -0,0 +1,49 @@
<testcase>
<info>
<keywords>
FTP
PASV
RETR
</keywords>
</info>
# Server-side
<reply>
<data>
data
to
see
that FTP
works
so does it?
</data>
</reply>
# Client-side
<client>
<server>
ftp
</server>
<name>
FTP fetch a file from the root directory with singlecwd
</name>
<command>
ftp://%HOSTIP:%FTPPORT//1226 --ftp-method singlecwd
</command>
</client>
# Verify data after the test has been "shot"
<verify>
<protocol>
USER anonymous
PASS ftp@example.com
PWD
CWD /
EPSV
TYPE I
SIZE 1226
RETR 1226
QUIT
</protocol>
</verify>
</testcase>

48
tests/data/test1227 Normal file
View File

@ -0,0 +1,48 @@
<testcase>
<info>
<keywords>
FTP
PASV
RETR
</keywords>
</info>
# Server-side
<reply>
<data>
data
to
see
that FTP
works
so does it?
</data>
</reply>
# Client-side
<client>
<server>
ftp
</server>
<name>
FTP fetch a file from the root directory with nocwd
</name>
<command>
ftp://%HOSTIP:%FTPPORT//1227 --ftp-method nocwd
</command>
</client>
# Verify data after the test has been "shot"
<verify>
<protocol>
USER anonymous
PASS ftp@example.com
PWD
EPSV
TYPE I
SIZE /1227
RETR /1227
QUIT
</protocol>
</verify>
</testcase>