Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:marvin24
curl
ftp-fix-HandleData-usage.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File ftp-fix-HandleData-usage.patch of Package curl
This patch moves FTP::file to struct ftp_conn, because is has to be dealt with at connection cleanup, at which time the struct HandleData could be used by another connection. Also, the unused char *urlpath member is removed from struct FTP. --- lib/ftp.c | 68 ++++++++++++++++++++++++++++++++++------------------------ lib/urldata.h | 3 -- 2 files changed, 41 insertions(+), 30 deletions(-) --- lib/ftp.c.orig +++ lib/ftp.c @@ -157,9 +157,9 @@ static void freedirs(struct connectdata free(ftpc->dirs); ftpc->dirs = NULL; } - if(ftp->file) { - free(ftp->file); - ftp->file = NULL; + if(ftpc->file) { + free(ftpc->file); + ftpc->file = NULL; } } @@ -1321,12 +1321,13 @@ static CURLcode ftp_state_post_type(stru { CURLcode result = CURLE_OK; struct FTP *ftp = conn->data->reqdata.proto.ftp; + struct ftp_conn *ftpc = &conn->proto.ftpc; if(ftp->no_transfer) { /* if a "head"-like request is being made */ /* we know ftp->file is a valid pointer to a file name */ - NBFTPSENDF(conn, "SIZE %s", ftp->file); + NBFTPSENDF(conn, "SIZE %s", ftpc->file); state(conn, FTP_SIZE); } @@ -1382,11 +1383,12 @@ static CURLcode ftp_state_post_mdtm(stru CURLcode result = CURLE_OK; struct FTP *ftp = conn->data->reqdata.proto.ftp; struct SessionHandle *data = conn->data; + struct ftp_conn *ftpc = &conn->proto.ftpc; /* If we have selected NOBODY and HEADER, it means that we only want file information. Which in FTP can't be much more than the file size and date. */ - if(conn->bits.no_body && data->set.include_header && ftp->file && + if(conn->bits.no_body && data->set.include_header && ftpc->file && ftp_need_type(conn, data->set.prefer_ascii)) { /* The SIZE command is _not_ RFC 959 specified, and therefor many servers may not support it! It is however the only way we have to get a file's @@ -1413,13 +1415,14 @@ static CURLcode ftp_state_post_cwd(struc CURLcode result = CURLE_OK; struct FTP *ftp = conn->data->reqdata.proto.ftp; struct SessionHandle *data = conn->data; + struct ftp_conn *ftpc = &conn->proto.ftpc; /* Requested time of file or time-depended transfer? */ - if((data->set.get_filetime || data->set.timecondition) && ftp->file) { + if((data->set.get_filetime || data->set.timecondition) && ftpc->file) { /* we have requested to get the modified-time of the file, this is a white spot as the MDTM is not mentioned in RFC959 */ - NBFTPSENDF(conn, "MDTM %s", ftp->file); + NBFTPSENDF(conn, "MDTM %s", ftpc->file); state(conn, FTP_MDTM); } @@ -1437,6 +1440,7 @@ static CURLcode ftp_state_ul_setup(struc CURLcode result = CURLE_OK; struct FTP *ftp = conn->data->reqdata.proto.ftp; struct SessionHandle *data = conn->data; + struct ftp_conn *ftpc = &conn->proto.ftpc; curl_off_t passed=0; if((data->reqdata.resume_from && !sizechecked) || @@ -1456,7 +1460,7 @@ static CURLcode ftp_state_ul_setup(struc if(data->reqdata.resume_from < 0 ) { /* Got no given size to start from, figure it out */ - NBFTPSENDF(conn, "SIZE %s", ftp->file); + NBFTPSENDF(conn, "SIZE %s", ftpc->file); state(conn, FTP_STOR_SIZE); return result; } @@ -1511,7 +1515,7 @@ static CURLcode ftp_state_ul_setup(struc } /* resume_from */ NBFTPSENDF(conn, data->set.ftp_append?"APPE %s":"STOR %s", - ftp->file); + ftpc->file); state(conn, FTP_STOR); @@ -1574,7 +1578,7 @@ static CURLcode ftp_state_quote(struct c if (ftp->no_transfer) state(conn, FTP_STOP); else { - NBFTPSENDF(conn, "SIZE %s", ftp->file); + NBFTPSENDF(conn, "SIZE %s", ftpc->file); state(conn, FTP_RETR_SIZE); } break; @@ -1876,6 +1880,7 @@ static CURLcode ftp_state_mdtm_resp(stru CURLcode result = CURLE_OK; struct SessionHandle *data=conn->data; struct FTP *ftp = data->reqdata.proto.ftp; + struct ftp_conn *ftpc = &conn->proto.ftpc; switch(ftpcode) { case 213: @@ -1901,7 +1906,7 @@ static CURLcode ftp_state_mdtm_resp(stru if(conn->bits.no_body && data->set.include_header && - ftp->file && + ftpc->file && data->set.get_filetime && (data->info.filetime>=0) ) { struct tm *tm; @@ -2006,6 +2011,7 @@ static CURLcode ftp_state_post_retr_size CURLcode result = CURLE_OK; struct SessionHandle *data=conn->data; struct FTP *ftp = data->reqdata.proto.ftp; + struct ftp_conn *ftpc = &conn->proto.ftpc; if (data->set.max_filesize && (filesize > data->set.max_filesize)) { failf(data, "Maximum file size exceeded"); @@ -2074,7 +2080,7 @@ static CURLcode ftp_state_post_retr_size } else { /* no resume */ - NBFTPSENDF(conn, "RETR %s", ftp->file); + NBFTPSENDF(conn, "RETR %s", ftpc->file); state(conn, FTP_RETR); } @@ -2119,6 +2125,7 @@ static CURLcode ftp_state_rest_resp(stru { CURLcode result = CURLE_OK; struct FTP *ftp = conn->data->reqdata.proto.ftp; + struct ftp_conn *ftpc = &conn->proto.ftpc; switch(instate) { case FTP_REST: @@ -2139,7 +2146,7 @@ static CURLcode ftp_state_rest_resp(stru result = CURLE_FTP_COULDNT_USE_REST; } else { - NBFTPSENDF(conn, "RETR %s", ftp->file); + NBFTPSENDF(conn, "RETR %s", ftpc->file); state(conn, FTP_RETR); } break; @@ -3087,7 +3094,7 @@ CURLcode Curl_ftp_done(struct connectdat ftpc->prevpath = NULL; /* no path */ } else { - size_t flen = ftp->file?strlen(ftp->file):0; /* file is "raw" already */ + size_t flen = ftpc->file?strlen(ftpc->file):0; /* file is "raw" already */ size_t dlen = strlen(path)-flen; if(dlen && !ftpc->cwdfail) { ftpc->prevpath = path; @@ -3365,6 +3372,7 @@ static CURLcode ftp_range(struct connect CURLcode Curl_ftp_nextconnect(struct connectdata *conn) { struct SessionHandle *data=conn->data; + struct ftp_conn *ftpc = &conn->proto.ftpc; CURLcode result = CURLE_OK; /* the ftp struct is inited in Curl_ftp_connect() */ @@ -3388,7 +3396,7 @@ CURLcode Curl_ftp_nextconnect(struct con result = ftp_range(conn); if(result) ; - else if((data->set.ftp_list_only) || !ftp->file) { + else if((data->set.ftp_list_only) || !ftpc->file) { /* The specified path ends with a slash, and therefore we think this is a directory that is requested, use LIST. But before that we need to set ASCII transfer mode. */ @@ -3685,12 +3693,16 @@ CURLcode Curl_ftp_disconnect(struct conn */ /* The FTP session may or may not have been allocated/setup at this point! */ + /* FIXME: checking for conn->data->reqdata.proto.ftp is not correct here, + * the reqdata structure could be used by another connection already */ if(conn->data->reqdata.proto.ftp) { (void)ftp_quit(conn); /* ignore errors on the QUIT */ if(ftpc->entrypath) { struct SessionHandle *data = conn->data; - data->state.most_recent_ftp_entrypath = NULL; + if (data->state.most_recent_ftp_entrypath == ftpc->entrypath) { + data->state.most_recent_ftp_entrypath = NULL; + } free(ftpc->entrypath); ftpc->entrypath = NULL; } @@ -3735,7 +3747,7 @@ CURLcode ftp_parse_url_path(struct conne switch(data->set.ftp_filemethod) { case FTPFILE_NOCWD: /* fastest, but less standard-compliant */ - ftp->file = data->reqdata.path; /* this is a full file path */ + ftpc->file = data->reqdata.path; /* this is a full file path */ break; case FTPFILE_SINGLECWD: @@ -3743,7 +3755,7 @@ CURLcode ftp_parse_url_path(struct conne if(!path_to_use[0]) { /* no dir, no file */ ftpc->dirdepth = 0; - ftp->file = NULL; + ftpc->file = NULL; break; } slash_pos=strrchr(cur_pos, '/'); @@ -3760,10 +3772,10 @@ CURLcode ftp_parse_url_path(struct conne return CURLE_OUT_OF_MEMORY; } ftpc->dirdepth = 1; /* we consider it to be a single dir */ - ftp->file = slash_pos ? slash_pos+1 : cur_pos; /* rest is file name */ + ftpc->file = slash_pos ? slash_pos+1 : cur_pos; /* rest is file name */ } else - ftp->file = cur_pos; /* this is a file name only */ + ftpc->file = cur_pos; /* this is a file name only */ break; default: /* allow pretty much anything */ @@ -3825,26 +3837,26 @@ CURLcode ftp_parse_url_path(struct conne } } } - ftp->file = cur_pos; /* the rest is the file name */ + ftpc->file = cur_pos; /* the rest is the file name */ } - if(ftp->file && *ftp->file) { - ftp->file = curl_easy_unescape(conn->data, ftp->file, 0, NULL); - if(NULL == ftp->file) { + if(ftpc->file && *ftpc->file) { + ftpc->file = curl_easy_unescape(conn->data, ftpc->file, 0, NULL); + if(NULL == ftpc->file) { freedirs(conn); failf(data, "no memory"); return CURLE_OUT_OF_MEMORY; } - if (isBadFtpString(ftp->file)) { + if (isBadFtpString(ftpc->file)) { freedirs(conn); return CURLE_URL_MALFORMAT; } } else - ftp->file=NULL; /* instead of point to a zero byte, we make it a NULL + ftpc->file=NULL; /* instead of point to a zero byte, we make it a NULL pointer */ - if(data->set.upload && !ftp->file && !ftp->no_transfer) { + if(data->set.upload && !ftpc->file && !ftp->no_transfer) { /* We need a file name when uploading. Return error! */ failf(data, "Uploading to a URL without a file name!"); return CURLE_URL_MALFORMAT; @@ -3861,7 +3873,7 @@ CURLcode ftp_parse_url_path(struct conne return CURLE_OUT_OF_MEMORY; } - dlen = strlen(path) - (ftp->file?strlen(ftp->file):0); + dlen = strlen(path) - (ftpc->file?strlen(ftpc->file):0); if((dlen == strlen(ftpc->prevpath)) && curl_strnequal(path, ftpc->prevpath, dlen)) { infof(data, "Request has same path as previous transfer\n"); --- lib/urldata.h.orig +++ lib/urldata.h @@ -359,8 +359,6 @@ struct FTP { curl_off_t *bytecountp; char *user; /* user name string */ char *passwd; /* password string */ - char *urlpath; /* the originally given path part of the URL */ - char *file; /* decoded file */ bool no_transfer; /* nothing was transfered, (possibly because a resumed transfer already was complete) */ curl_off_t downloadsize; @@ -373,6 +371,7 @@ struct ftp_conn { char **dirs; /* realloc()ed array for path components */ int dirdepth; /* number of entries used in the 'dirs' array */ int diralloc; /* number of entries allocated for the 'dirs' array */ + char *file; /* decoded file */ char *cache; /* data cache between getresponse()-calls */ curl_off_t cache_size; /* size of cache in bytes */ bool dont_check; /* Set to TRUE to prevent the final (post-transfer)
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor