summaryrefslogtreecommitdiff
path: root/lib/ftp.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2019-09-12 17:50:21 +0200
committerDaniel Stenberg <daniel@haxx.se>2019-09-12 17:50:21 +0200
commit2e445f90983588597a6034239b79ef80304bcf53 (patch)
tree1ad9785098aa4a8fcd2628b8cb1b710a25c87767 /lib/ftp.c
parent4e3dfe3323bedc534024cff7ee5d27771958895d (diff)
downloadcurl-2e445f90983588597a6034239b79ef80304bcf53.tar.gz
FTP: allow "rubbish" prepended to the SIZE responsebagder/ftp-size-rubbish
It is debatable whether this is allowed by the protocol but apparently there are legacy proprietary servers doing this. Reported-by: Philippe Marguinaud
Diffstat (limited to 'lib/ftp.c')
-rw-r--r--lib/ftp.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/ftp.c b/lib/ftp.c
index e807a2acd..ce16e8bfd 100644
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -2242,9 +2242,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