From 44585908f127cc71af6361bb63ca8bf46d0324c5 Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Tue, 12 Jun 2018 13:27:38 -0600 Subject: [PATCH 1/3] additional free's and memory management --- src/wolfsftp.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/wolfsftp.c b/src/wolfsftp.c index 4a733c6..af5404d 100644 --- a/src/wolfsftp.c +++ b/src/wolfsftp.c @@ -409,15 +409,18 @@ static int wolfSSH_SFTP_RecvRealPath(WOLFSSH* ssh, int reqId, int maxSz) return WS_MEMORY_E; } if (wolfSSH_stream_read(ssh, (byte*)dir, maxSz) < 0) { + WFREE(dir, ssh->ctx->heap, DYNTYPE_BUFFER); return WS_FATAL_ERROR; } ato32((byte*)dir, &rSz); if (rSz > WOLFSSH_MAX_FILENAME) { + WFREE(dir, ssh->ctx->heap, DYNTYPE_BUFFER); return WS_BUFFER_E; } WMEMCPY(r, dir + UINT32_SZ, rSz); r[rSz] = '\0'; + WFREE(dir, ssh->ctx->heap, DYNTYPE_BUFFER); /* get working directory in the case of receiving non absolute path */ if (r[0] != '/') { @@ -468,8 +471,10 @@ static int wolfSSH_SFTP_RecvRealPath(WOLFSSH* ssh, int reqId, int maxSz) /* send out buffer */ if (wolfSSH_stream_send(ssh, out, maxSz) < 0) { + WFREE(out, ssh->ctx->heap, DYNTYPE_BUFFER); return WS_FATAL_ERROR; } + WFREE(out, ssh->ctx->heap, DYNTYPE_BUFFER); return WS_SUCCESS; } @@ -2006,8 +2011,13 @@ static int wolfSSH_SFTP_DoStatus(WOLFSSH* ssh, word32 reqId) { byte* s = (byte*)WMALLOC(sz + 1, ssh->ctx->heap, DYNTYPE_BUFFER); + if (s == NULL) { + return WS_MEMORY_E; + } + ret = wolfSSH_stream_read(ssh, s, sz); if (ret < 0) { + WFREE(s, ssh->ctx->heap, DYNTYPE_BUFFER); return ret; } @@ -2026,8 +2036,13 @@ static int wolfSSH_SFTP_DoStatus(WOLFSSH* ssh, word32 reqId) if (sz > 0) { byte* s = (byte*)WMALLOC(sz + 1, ssh->ctx->heap, DYNTYPE_BUFFER); + if (s == NULL) { + return WS_MEMORY_E; + } + ret = wolfSSH_stream_read(ssh, s, sz); if (ret < 0) { + WFREE(s, ssh->ctx->heap, DYNTYPE_BUFFER); return ret; } From f80617f43c2e4cfda3309b07818167ff23f5e09a Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Thu, 7 Jun 2018 20:50:06 -0600 Subject: [PATCH 2/3] return value with write to file error --- src/wolfsftp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wolfsftp.c b/src/wolfsftp.c index af5404d..48d8aef 100644 --- a/src/wolfsftp.c +++ b/src/wolfsftp.c @@ -1271,7 +1271,7 @@ int wolfSSH_SFTP_RecvWrite(WOLFSSH* ssh, int reqId, word32 maxSz) WLOG(WS_LOG_SFTP, "Error writing to file"); wolfSSH_SFTP_SendStatus(ssh, WOLFSSH_FTP_FAILURE, reqId, "Write File Error", "English"); - return WS_FATAL_ERROR; + return WS_INVALID_STATE_E; } wolfSSH_SFTP_SendStatus(ssh, WOLFSSH_FTP_OK, reqId, From 0fb9a76e549143227011835c7187b447f89d6466 Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Thu, 7 Jun 2018 10:16:49 -0600 Subject: [PATCH 3/3] alter error value for rename failure --- src/wolfsftp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wolfsftp.c b/src/wolfsftp.c index 48d8aef..9495678 100644 --- a/src/wolfsftp.c +++ b/src/wolfsftp.c @@ -1549,7 +1549,7 @@ int wolfSSH_SFTP_RecvRename(WOLFSSH* ssh, int reqId, word32 maxSz) if (ret == WS_SUCCESS && WRENAME(old, nw) < 0) { WLOG(WS_LOG_SFTP, "Error renaming file"); - ret = WS_FATAL_ERROR; + ret = WS_BAD_FILE_E; } /* Let the client know the results from trying to rename the file */