libssh2: use the filename buffer when getting the homedir
Avoids having to use a big stack buffer for this. Closes #15285
This commit is contained in:
parent
083b4ab6e4
commit
facf59c30e
@ -2046,21 +2046,18 @@ static CURLcode ssh_statemachine(struct Curl_easy *data, bool *block)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SSH_SFTP_REALPATH:
|
case SSH_SFTP_REALPATH:
|
||||||
{
|
|
||||||
char tempHome[CURL_PATH_MAX];
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the "home" directory
|
* Get the "home" directory
|
||||||
*/
|
*/
|
||||||
rc = sftp_libssh2_realpath(sshc->sftp_session, ".",
|
rc = sftp_libssh2_realpath(sshc->sftp_session, ".",
|
||||||
tempHome, CURL_PATH_MAX-1);
|
sshp->readdir_filename, CURL_PATH_MAX);
|
||||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(rc > 0) {
|
if(rc > 0) {
|
||||||
/* It seems that this string is not always NULL terminated */
|
/* It seems that this string is not always NULL terminated */
|
||||||
tempHome[rc] = '\0';
|
sshp->readdir_filename[rc] = '\0';
|
||||||
sshc->homedir = strdup(tempHome);
|
sshc->homedir = strdup(sshp->readdir_filename);
|
||||||
if(!sshc->homedir) {
|
if(!sshc->homedir) {
|
||||||
state(data, SSH_SFTP_CLOSE);
|
state(data, SSH_SFTP_CLOSE);
|
||||||
sshc->actualcode = CURLE_OUT_OF_MEMORY;
|
sshc->actualcode = CURLE_OUT_OF_MEMORY;
|
||||||
@ -2083,7 +2080,7 @@ static CURLcode ssh_statemachine(struct Curl_easy *data, bool *block)
|
|||||||
state(data, SSH_STOP);
|
state(data, SSH_STOP);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
/* This is the last step in the SFTP connect phase. Do note that while
|
/* This is the last step in the SFTP connect phase. Do note that while
|
||||||
we get the homedir here, we get the "workingpath" in the DO action
|
we get the homedir here, we get the "workingpath" in the DO action
|
||||||
since the homedir will remain the same between request but the
|
since the homedir will remain the same between request but the
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user