aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2019-09-12 17:50:21 +0200
committerDaniel Stenberg <daniel@haxx.se>2019-09-13 14:21:00 +0200
commit65f5b958c95d538a9b205e2753a476d1a7c89179 (patch)
treedc6894cf318ac173b56bfa62a708049d41feb36e /lib
parentacf1d2acd17b194966be41e848ffd48b02ecef0c (diff)
FTP: allow "rubbish" prepended to the SIZE response
This is a protocol violation but apparently there are legacy proprietary servers doing this. Added test 336 and 337 to verify. Reported-by: Philippe Marguinaud Closes #4339
Diffstat (limited to 'lib')
-rw-r--r--lib/ftp.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/ftp.c b/lib/ftp.c
index 0793dc1f3..00233a80d 100644
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -2244,9 +2244,25 @@ static CURLcode ftp_state_size_resp(struct connectdata *conn,
char *buf = data->state.buffer;
/* get the size from the ascii string: */
- if(ftpcode == 213)
+ if(ftpcode == 213) {
+ /* To allow servers to prepend "rubbish" in the response string, we scan
+ for all the digits at the end of the response and parse only those as a
+ number. */
+ char *start = &buf[4];
+ char *fdigit = strchr(start, '\r');
+ if(fdigit) {
+ do
+ fdigit--;
+ while(ISDIGIT(*fdigit) && (fdigit > start));
+ if(!ISDIGIT(*fdigit))
+ fdigit++;
+ }
+ else
+ fdigit = start;
/* ignores parsing errors, which will make the size remain unknown */
- (void)curlx_strtoofft(buf + 4, NULL, 0, &filesize);
+ (void)curlx_strtoofft(fdigit, NULL, 0, &filesize);
+
+ }
if(instate == FTP_SIZE) {
#ifdef CURL_FTP_HTTPSTYLE_HEAD