summaryrefslogtreecommitdiff
path: root/lib/ftp.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2018-04-19 15:47:05 +0200
committerDaniel Stenberg <daniel@haxx.se>2018-04-23 22:52:52 +0200
commitabbc8457d85aca74b7cfda1d394b0844932b2934 (patch)
tree46f2c7e16eefe4d557127b4769f4c9ffa16210ce /lib/ftp.c
parent98a768f0a6d23e6d3e209fc543d60e260dbcc46b (diff)
downloadcurl-abbc8457d85aca74b7cfda1d394b0844932b2934.tar.gz
ftplistparser: keep state between invokes
Fixes FTP wildcard parsing when doing over a number of read buffers. Regression from f786d1f14 Reported-by: wncboy on github Fixes #2445 Closes #2519
Diffstat (limited to 'lib/ftp.c')
-rw-r--r--lib/ftp.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/lib/ftp.c b/lib/ftp.c
index e53e1b3b3..a7830b9ce 100644
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -3699,7 +3699,7 @@ static CURLcode init_wc_data(struct connectdata *conn)
char *path = conn->data->state.path;
struct WildcardData *wildcard = &(conn->data->wildcard);
CURLcode result = CURLE_OK;
- struct ftp_wc *ftpwc;
+ struct ftp_wc *ftpwc = NULL;
last_slash = strrchr(conn->data->state.path, '/');
if(last_slash) {
@@ -3734,16 +3734,15 @@ static CURLcode init_wc_data(struct connectdata *conn)
/* allocate ftp protocol specific wildcard data */
ftpwc = calloc(1, sizeof(struct ftp_wc));
if(!ftpwc) {
- Curl_safefree(wildcard->pattern);
- return CURLE_OUT_OF_MEMORY;
+ result = CURLE_OUT_OF_MEMORY;
+ goto fail;
}
/* INITIALIZE parselist structure */
ftpwc->parser = Curl_ftp_parselist_data_alloc();
if(!ftpwc->parser) {
- Curl_safefree(wildcard->pattern);
- free(ftpwc);
- return CURLE_OUT_OF_MEMORY;
+ result = CURLE_OUT_OF_MEMORY;
+ goto fail;
}
wildcard->protdata = ftpwc; /* put it to the WildcardData tmp pointer */
@@ -3756,20 +3755,13 @@ static CURLcode init_wc_data(struct connectdata *conn)
/* try to parse ftp url */
result = ftp_parse_url_path(conn);
if(result) {
- Curl_safefree(wildcard->pattern);
- wildcard->dtor(wildcard->protdata);
- wildcard->dtor = ZERO_NULL;
- wildcard->protdata = NULL;
- return result;
+ goto fail;
}
wildcard->path = strdup(conn->data->state.path);
if(!wildcard->path) {
- Curl_safefree(wildcard->pattern);
- wildcard->dtor(wildcard->protdata);
- wildcard->dtor = ZERO_NULL;
- wildcard->protdata = NULL;
- return CURLE_OUT_OF_MEMORY;
+ result = CURLE_OUT_OF_MEMORY;
+ goto fail;
}
/* backup old write_function */
@@ -3783,6 +3775,17 @@ static CURLcode init_wc_data(struct connectdata *conn)
infof(conn->data, "Wildcard - Parsing started\n");
return CURLE_OK;
+
+ fail:
+ if(ftpwc) {
+ Curl_ftp_parselist_data_free(&ftpwc->parser);
+ free(ftpwc);
+ }
+ Curl_safefree(wildcard->pattern);
+ wildcard->dtor(wildcard->protdata);
+ wildcard->dtor = ZERO_NULL;
+ wildcard->protdata = NULL;
+ return result;
}
/* This is called recursively */
@@ -3903,6 +3906,8 @@ static CURLcode wc_statemach(struct connectdata *conn)
case CURLWC_DONE:
case CURLWC_ERROR:
case CURLWC_CLEAR:
+ if(wildcard->dtor)
+ wildcard->dtor(wildcard->protdata);
break;
}