Skip to content

Commit

Permalink
ftp: never set data->set.ftp_append outside setopt
Browse files Browse the repository at this point in the history
Since the set value then risks getting used like that when the easy
handle is reused by the application.

Also: renamed the struct field from 'ftp_append' to 'remote_append'
since it is also used for SSH protocols.

Closes #6579
  • Loading branch information
bagder committed Feb 8, 2021
1 parent d836d36 commit 0c51036
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/ftp.c
Expand Up @@ -1578,6 +1578,7 @@ static CURLcode ftp_state_ul_setup(struct Curl_easy *data,
struct connectdata *conn = data->conn;
struct FTP *ftp = data->req.p.ftp;
struct ftp_conn *ftpc = &conn->proto.ftpc;
bool append = data->set.remote_append;

if((data->state.resume_from && !sizechecked) ||
((data->state.resume_from > 0) && sizechecked)) {
Expand All @@ -1604,7 +1605,7 @@ static CURLcode ftp_state_ul_setup(struct Curl_easy *data,
}

/* enable append */
data->set.ftp_append = TRUE;
append = TRUE;

/* Let's read off the proper amount of bytes from the input. */
if(conn->seek_func) {
Expand Down Expand Up @@ -1661,8 +1662,7 @@ static CURLcode ftp_state_ul_setup(struct Curl_easy *data,
/* we've passed, proceed as normal */
} /* resume_from */

result = Curl_pp_sendf(data, &ftpc->pp,
data->set.ftp_append?"APPE %s":"STOR %s",
result = Curl_pp_sendf(data, &ftpc->pp, append?"APPE %s":"STOR %s",
ftpc->file);
if(!result)
state(data, FTP_STOR);
Expand Down
2 changes: 1 addition & 1 deletion lib/setopt.c
Expand Up @@ -1165,7 +1165,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
* We want to upload and append to an existing file. Used for FTP and
* SFTP.
*/
data->set.ftp_append = (0 != va_arg(param, long)) ? TRUE : FALSE;
data->set.remote_append = (0 != va_arg(param, long)) ? TRUE : FALSE;
break;

#ifndef CURL_DISABLE_FTP
Expand Down
2 changes: 1 addition & 1 deletion lib/urldata.h
Expand Up @@ -1792,7 +1792,7 @@ struct UserDefined {
BIT(get_filetime); /* get the time and get of the remote file */
BIT(tunnel_thru_httpproxy); /* use CONNECT through a HTTP proxy */
BIT(prefer_ascii); /* ASCII rather than binary */
BIT(ftp_append); /* append, not overwrite, on upload */
BIT(remote_append); /* append, not overwrite, on upload */
BIT(ftp_list_only); /* switch FTP command for listing directories */
#ifndef CURL_DISABLE_FTP
BIT(ftp_use_port); /* use the FTP PORT command */
Expand Down
2 changes: 1 addition & 1 deletion lib/vssh/libssh.c
Expand Up @@ -1224,7 +1224,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
}
}

if(data->set.ftp_append)
if(data->set.remote_append)
/* Try to open for append, but create if nonexisting */
flags = O_WRONLY|O_CREAT|O_APPEND;
else if(data->state.resume_from > 0)
Expand Down
2 changes: 1 addition & 1 deletion lib/vssh/libssh2.c
Expand Up @@ -1880,7 +1880,7 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
}
}

if(data->set.ftp_append)
if(data->set.remote_append)
/* Try to open for append, but create if nonexisting */
flags = LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT|LIBSSH2_FXF_APPEND;
else if(data->state.resume_from > 0)
Expand Down
2 changes: 1 addition & 1 deletion lib/vssh/wolfssh.c
Expand Up @@ -585,7 +585,7 @@ static CURLcode wssh_statemach_act(struct Curl_easy *data, bool *block)
}
}

if(data->set.ftp_append)
if(data->set.remote_append)
/* Try to open for append, but create if nonexisting */
flags = WOLFSSH_FXF_WRITE|WOLFSSH_FXF_CREAT|WOLFSSH_FXF_APPEND;
else if(data->state.resume_from > 0)
Expand Down

0 comments on commit 0c51036

Please sign in to comment.