[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnurl] 47/125: sftp: allow quoted commands to use relative
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnurl] 47/125: sftp: allow quoted commands to use relative paths |
Date: |
Sun, 21 Jan 2018 23:41:42 +0100 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to branch master
in repository gnurl.
commit a4a56ec93e727293f30074f4eac24c19110bd39d
Author: John DeHelian <address@hidden>
AuthorDate: Fri Dec 8 11:31:01 2017 -0500
sftp: allow quoted commands to use relative paths
Closes #1900
---
lib/curl_path.c | 34 +++++++++++++++++++++++++---------
lib/curl_path.h | 3 +--
lib/ssh-libssh.c | 8 ++++----
lib/ssh.c | 8 ++++----
4 files changed, 34 insertions(+), 19 deletions(-)
diff --git a/lib/curl_path.c b/lib/curl_path.c
index cd6592096..e843deac7 100644
--- a/lib/curl_path.c
+++ b/lib/curl_path.c
@@ -110,21 +110,25 @@ CURLcode Curl_getworkingpath(struct connectdata *conn,
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* 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;
char quot;
unsigned int i, j;
+ size_t fullPathLength, pathLength;
+ bool relativePath = false;
static const char WHITESPACE[] = " \t\r\n";
- cp += strspn(cp, WHITESPACE);
if(!*cp) {
- *cpp = cp;
+ *cpp = NULL;
*path = NULL;
return CURLE_QUOTE_ERROR;
}
-
- *path = malloc(strlen(cp) + 1);
+ /* Ignore leading whitespace */
+ 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)
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);
}
else {
- /* Read to end of filename */
+ /* Read to end of filename - either to white space or terminator */
end = strpbrk(cp, WHITESPACE);
if(end == NULL)
end = strchr(cp, '\0');
+ /* return pointer to second parameter if it exists */
*cpp = end + strspn(end, WHITESPACE);
-
- memcpy(*path, cp, end - cp);
- (*path)[end - cp] = '\0';
+ pathLength = 0;
+ relativePath = (cp[0] == '/' && cp[1] == '~' && cp[2] == '/');
+ /* 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;
diff --git a/lib/curl_path.h b/lib/curl_path.h
index 3ce16eb88..f9d432750 100644
--- a/lib/curl_path.h
+++ b/lib/curl_path.h
@@ -41,5 +41,4 @@ CURLcode Curl_getworkingpath(struct connectdata *conn,
char *homedir,
char **path);
-CURLcode
-Curl_get_pathname(const char **cpp, char **path);
+CURLcode Curl_get_pathname(const char **cpp, char **path, char *homedir);
diff --git a/lib/ssh-libssh.c b/lib/ssh-libssh.c
index 822a7419c..fb49a22d5 100644
--- a/lib/ssh-libssh.c
+++ b/lib/ssh-libssh.c
@@ -2534,7 +2534,7 @@ static void sftp_quote(struct connectdata *conn)
* also, every command takes at least one argument so we get that
* 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 == CURLE_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 */
/* 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 == CURLE_OUT_OF_MEMORY)
failf(data, "Out of memory");
@@ -2581,7 +2581,7 @@ static void sftp_quote(struct connectdata *conn)
/* symbolic linking */
/* sshc->quote_path1 is the source */
/* 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 == CURLE_OUT_OF_MEMORY)
failf(data, "Out of memory");
@@ -2605,7 +2605,7 @@ static void sftp_quote(struct connectdata *conn)
/* rename file */
/* first param is the source 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 == CURLE_OUT_OF_MEMORY)
failf(data, "Out of memory");
diff --git a/lib/ssh.c b/lib/ssh.c
index a4dd878bf..bf07432bd 100644
--- a/lib/ssh.c
+++ b/lib/ssh.c
@@ -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
* 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 == CURLE_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 */
/* 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 == CURLE_OUT_OF_MEMORY)
failf(data, "Out of memory");
@@ -1252,7 +1252,7 @@ static CURLcode ssh_statemach_act(struct connectdata
*conn, bool *block)
/* symbolic linking */
/* sshc->quote_path1 is the source */
/* 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 == CURLE_OUT_OF_MEMORY)
failf(data, "Out of memory");
@@ -1277,7 +1277,7 @@ static CURLcode ssh_statemach_act(struct connectdata
*conn, bool *block)
/* rename file */
/* first param is the source 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 == CURLE_OUT_OF_MEMORY)
failf(data, "Out of memory");
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnurl] 114/125: curl_fnmatch: only allow 5 '*' sections in a single pattern, (continued)
- [GNUnet-SVN] [gnurl] 114/125: curl_fnmatch: only allow 5 '*' sections in a single pattern, gnunet, 2018/01/21
- [GNUnet-SVN] [gnurl] 75/125: examples/rtsp: fix error handling macros, gnunet, 2018/01/21
- [GNUnet-SVN] [gnurl] 117/125: openssl: fix potential memory leak in SSLKEYLOGFILE logic, gnunet, 2018/01/21
- [GNUnet-SVN] [gnurl] 12/125: libssh: added SFTP support, gnunet, 2018/01/21
- [GNUnet-SVN] [gnurl] 122/125: TODO: two possible name resolver improvements, gnunet, 2018/01/21
- [GNUnet-SVN] [gnurl] 118/125: SSH: Fix state machine for ssh-agent authentication, gnunet, 2018/01/21
- [GNUnet-SVN] [gnurl] 07/125: Added support for libssh SSH SCP back-end, gnunet, 2018/01/21
- [GNUnet-SVN] [gnurl] 42/125: curl.h: remove incorrect comment about ERRORBUFFER, gnunet, 2018/01/21
- [GNUnet-SVN] [gnurl] 46/125: CURLOPT_PRIVATE.3: fix grammar, gnunet, 2018/01/21
- [GNUnet-SVN] [gnurl] 39/125: BINDINGS: another PostgreSQL client, gnunet, 2018/01/21
- [GNUnet-SVN] [gnurl] 47/125: sftp: allow quoted commands to use relative paths,
gnunet <=
- [GNUnet-SVN] [gnurl] 38/125: CONNECT: keep close connection flag in http_connect_state struct, gnunet, 2018/01/21
- [GNUnet-SVN] [gnurl] 78/125: build-wolfssl.bat: Added support for VC15, gnunet, 2018/01/21
- [GNUnet-SVN] [gnurl] 90/125: openssl: fix memory leak of SSLKEYLOGFILE filename, gnunet, 2018/01/21
- [GNUnet-SVN] [gnurl] 98/125: http2: fix incorrect trailer buffer size, gnunet, 2018/01/21
- [GNUnet-SVN] [gnurl] 70/125: rand: add a clang-analyzer work-around, gnunet, 2018/01/21
- [GNUnet-SVN] [gnurl] 66/125: libssh: fix a syntax error in configure.ac, gnunet, 2018/01/21
- [GNUnet-SVN] [gnurl] 72/125: brotli: allow compiling with version 0.6.0., gnunet, 2018/01/21
- [GNUnet-SVN] [gnurl] 111/125: CURLOPT_TCP_NODELAY.3: fix typo, gnunet, 2018/01/21
- [GNUnet-SVN] [gnurl] 104/125: test393: verify --max-filesize with excessive Content-Length, gnunet, 2018/01/21
- [GNUnet-SVN] [gnurl] 109/125: openssl: enable SSLKEYLOGFILE support by default, gnunet, 2018/01/21