mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 23:58:49 -05:00
parent
9fb5a943f5
commit
a4a56ec93e
@ -110,21 +110,25 @@ CURLcode Curl_getworkingpath(struct connectdata *conn,
|
|||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
CURLcode Curl_get_pathname(const char **cpp, char **path)
|
CURLcode Curl_get_pathname(const char **cpp, char **path, char *homedir)
|
||||||
{
|
{
|
||||||
const char *cp = *cpp, *end;
|
const char *cp = *cpp, *end;
|
||||||
char quot;
|
char quot;
|
||||||
unsigned int i, j;
|
unsigned int i, j;
|
||||||
|
size_t fullPathLength, pathLength;
|
||||||
|
bool relativePath = false;
|
||||||
static const char WHITESPACE[] = " \t\r\n";
|
static const char WHITESPACE[] = " \t\r\n";
|
||||||
|
|
||||||
cp += strspn(cp, WHITESPACE);
|
|
||||||
if(!*cp) {
|
if(!*cp) {
|
||||||
*cpp = cp;
|
*cpp = NULL;
|
||||||
*path = NULL;
|
*path = NULL;
|
||||||
return CURLE_QUOTE_ERROR;
|
return CURLE_QUOTE_ERROR;
|
||||||
}
|
}
|
||||||
|
/* Ignore leading whitespace */
|
||||||
*path = malloc(strlen(cp) + 1);
|
cp += strspn(cp, WHITESPACE);
|
||||||
|
/* Allocate enough space for home directory and filename + separator */
|
||||||
|
fullPathLength = strlen(cp) + strlen(homedir) + 2;
|
||||||
|
*path = malloc(fullPathLength);
|
||||||
if(*path == NULL)
|
if(*path == NULL)
|
||||||
return CURLE_OUT_OF_MEMORY;
|
return CURLE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
@ -162,14 +166,26 @@ CURLcode Curl_get_pathname(const char **cpp, char **path)
|
|||||||
*cpp = cp + i + strspn(cp + i, WHITESPACE);
|
*cpp = cp + i + strspn(cp + i, WHITESPACE);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Read to end of filename */
|
/* Read to end of filename - either to white space or terminator */
|
||||||
end = strpbrk(cp, WHITESPACE);
|
end = strpbrk(cp, WHITESPACE);
|
||||||
if(end == NULL)
|
if(end == NULL)
|
||||||
end = strchr(cp, '\0');
|
end = strchr(cp, '\0');
|
||||||
|
/* return pointer to second parameter if it exists */
|
||||||
*cpp = end + strspn(end, WHITESPACE);
|
*cpp = end + strspn(end, WHITESPACE);
|
||||||
|
pathLength = 0;
|
||||||
memcpy(*path, cp, end - cp);
|
relativePath = (cp[0] == '/' && cp[1] == '~' && cp[2] == '/');
|
||||||
(*path)[end - cp] = '\0';
|
/* Handling for relative path - prepend home directory */
|
||||||
|
if(relativePath) {
|
||||||
|
strcpy(*path, homedir);
|
||||||
|
pathLength = strlen(homedir);
|
||||||
|
(*path)[pathLength++] = '/';
|
||||||
|
(*path)[pathLength] = '\0';
|
||||||
|
cp += 3;
|
||||||
|
}
|
||||||
|
/* Copy path name up until first "white space" */
|
||||||
|
memcpy(&(*path)[pathLength], cp, (int)(end - cp));
|
||||||
|
pathLength += (int)(end - cp);
|
||||||
|
(*path)[pathLength] = '\0';
|
||||||
}
|
}
|
||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
|
|
||||||
|
@ -41,5 +41,4 @@ CURLcode Curl_getworkingpath(struct connectdata *conn,
|
|||||||
char *homedir,
|
char *homedir,
|
||||||
char **path);
|
char **path);
|
||||||
|
|
||||||
CURLcode
|
CURLcode Curl_get_pathname(const char **cpp, char **path, char *homedir);
|
||||||
Curl_get_pathname(const char **cpp, char **path);
|
|
||||||
|
@ -2534,7 +2534,7 @@ static void sftp_quote(struct connectdata *conn)
|
|||||||
* also, every command takes at least one argument so we get that
|
* also, every command takes at least one argument so we get that
|
||||||
* first argument right now
|
* first argument right now
|
||||||
*/
|
*/
|
||||||
result = Curl_get_pathname(&cp, &sshc->quote_path1);
|
result = Curl_get_pathname(&cp, &sshc->quote_path1, sshc->homedir);
|
||||||
if(result) {
|
if(result) {
|
||||||
if(result == CURLE_OUT_OF_MEMORY)
|
if(result == CURLE_OUT_OF_MEMORY)
|
||||||
failf(data, "Out of memory");
|
failf(data, "Out of memory");
|
||||||
@ -2559,7 +2559,7 @@ static void sftp_quote(struct connectdata *conn)
|
|||||||
|
|
||||||
/* sshc->quote_path1 contains the mode to set */
|
/* sshc->quote_path1 contains the mode to set */
|
||||||
/* get the destination */
|
/* get the destination */
|
||||||
result = Curl_get_pathname(&cp, &sshc->quote_path2);
|
result = Curl_get_pathname(&cp, &sshc->quote_path2, sshc->homedir);
|
||||||
if(result) {
|
if(result) {
|
||||||
if(result == CURLE_OUT_OF_MEMORY)
|
if(result == CURLE_OUT_OF_MEMORY)
|
||||||
failf(data, "Out of memory");
|
failf(data, "Out of memory");
|
||||||
@ -2581,7 +2581,7 @@ static void sftp_quote(struct connectdata *conn)
|
|||||||
/* symbolic linking */
|
/* symbolic linking */
|
||||||
/* sshc->quote_path1 is the source */
|
/* sshc->quote_path1 is the source */
|
||||||
/* get the destination */
|
/* get the destination */
|
||||||
result = Curl_get_pathname(&cp, &sshc->quote_path2);
|
result = Curl_get_pathname(&cp, &sshc->quote_path2, sshc->homedir);
|
||||||
if(result) {
|
if(result) {
|
||||||
if(result == CURLE_OUT_OF_MEMORY)
|
if(result == CURLE_OUT_OF_MEMORY)
|
||||||
failf(data, "Out of memory");
|
failf(data, "Out of memory");
|
||||||
@ -2605,7 +2605,7 @@ static void sftp_quote(struct connectdata *conn)
|
|||||||
/* rename file */
|
/* rename file */
|
||||||
/* first param is the source path */
|
/* first param is the source path */
|
||||||
/* second param is the dest. path */
|
/* second param is the dest. path */
|
||||||
result = Curl_get_pathname(&cp, &sshc->quote_path2);
|
result = Curl_get_pathname(&cp, &sshc->quote_path2, sshc->homedir);
|
||||||
if(result) {
|
if(result) {
|
||||||
if(result == CURLE_OUT_OF_MEMORY)
|
if(result == CURLE_OUT_OF_MEMORY)
|
||||||
failf(data, "Out of memory");
|
failf(data, "Out of memory");
|
||||||
|
@ -1205,7 +1205,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
|
|||||||
* also, every command takes at least one argument so we get that
|
* also, every command takes at least one argument so we get that
|
||||||
* first argument right now
|
* first argument right now
|
||||||
*/
|
*/
|
||||||
result = Curl_get_pathname(&cp, &sshc->quote_path1);
|
result = Curl_get_pathname(&cp, &sshc->quote_path1, sshc->homedir);
|
||||||
if(result) {
|
if(result) {
|
||||||
if(result == CURLE_OUT_OF_MEMORY)
|
if(result == CURLE_OUT_OF_MEMORY)
|
||||||
failf(data, "Out of memory");
|
failf(data, "Out of memory");
|
||||||
@ -1230,7 +1230,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
|
|||||||
|
|
||||||
/* sshc->quote_path1 contains the mode to set */
|
/* sshc->quote_path1 contains the mode to set */
|
||||||
/* get the destination */
|
/* get the destination */
|
||||||
result = Curl_get_pathname(&cp, &sshc->quote_path2);
|
result = Curl_get_pathname(&cp, &sshc->quote_path2, sshc->homedir);
|
||||||
if(result) {
|
if(result) {
|
||||||
if(result == CURLE_OUT_OF_MEMORY)
|
if(result == CURLE_OUT_OF_MEMORY)
|
||||||
failf(data, "Out of memory");
|
failf(data, "Out of memory");
|
||||||
@ -1252,7 +1252,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
|
|||||||
/* symbolic linking */
|
/* symbolic linking */
|
||||||
/* sshc->quote_path1 is the source */
|
/* sshc->quote_path1 is the source */
|
||||||
/* get the destination */
|
/* get the destination */
|
||||||
result = Curl_get_pathname(&cp, &sshc->quote_path2);
|
result = Curl_get_pathname(&cp, &sshc->quote_path2, sshc->homedir);
|
||||||
if(result) {
|
if(result) {
|
||||||
if(result == CURLE_OUT_OF_MEMORY)
|
if(result == CURLE_OUT_OF_MEMORY)
|
||||||
failf(data, "Out of memory");
|
failf(data, "Out of memory");
|
||||||
@ -1277,7 +1277,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
|
|||||||
/* rename file */
|
/* rename file */
|
||||||
/* first param is the source path */
|
/* first param is the source path */
|
||||||
/* second param is the dest. path */
|
/* second param is the dest. path */
|
||||||
result = Curl_get_pathname(&cp, &sshc->quote_path2);
|
result = Curl_get_pathname(&cp, &sshc->quote_path2, sshc->homedir);
|
||||||
if(result) {
|
if(result) {
|
||||||
if(result == CURLE_OUT_OF_MEMORY)
|
if(result == CURLE_OUT_OF_MEMORY)
|
||||||
failf(data, "Out of memory");
|
failf(data, "Out of memory");
|
||||||
|
Loading…
Reference in New Issue
Block a user