From 0e11a143fd72ebc594f050f280bb0085c8510bc9 Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Thu, 23 May 2024 13:49:48 -0600 Subject: [PATCH 1/2] error out if unable to open the local file when doing a SCP send --- src/wolfscp.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/wolfscp.c b/src/wolfscp.c index 33a55580a..6773ece19 100644 --- a/src/wolfscp.c +++ b/src/wolfscp.c @@ -2634,6 +2634,7 @@ static int ScpProcessEntry(WOLFSSH* ssh, char* fileName, word64* mTime, * WS_SCP_EXIT_DIR_FINAL - return when recursive directory transfer * is complete. * WS_SCP_ABORT - abort file transfer request + * WS_BAD_FILE_E - local file open error hit */ int wsScpSendCallback(WOLFSSH* ssh, int state, const char* peerRequest, char* fileName, word32 fileNameSz, word64* mTime, word64* aTime, @@ -2672,7 +2673,7 @@ int wsScpSendCallback(WOLFSSH* ssh, int state, const char* peerRequest, WLOG(WS_LOG_ERROR, "scp: unable to open file, abort"); wolfSSH_SetScpErrorMsg(ssh, "unable to open file for reading"); - ret = WS_SCP_ABORT; + ret = WS_BAD_FILE_E; } if (ret == WS_SUCCESS) { @@ -2694,17 +2695,21 @@ int wsScpSendCallback(WOLFSSH* ssh, int state, const char* peerRequest, if (ret == WS_SUCCESS) ret = ExtractFileName(peerRequest, fileName, fileNameSz); - if (ret == WS_SUCCESS && sendCtx != NULL && sendCtx->fp != NULL) { - /* If it is an empty file, do not read. */ - if (*totalFileSz != 0) { - ret = (word32)WFREAD(ssh->fs, buf, 1, bufSz, sendCtx->fp); - if (ret == 0) { /* handle unexpected case */ - ret = WS_EOF; + if (ret == WS_SUCCESS) { + if (sendCtx != NULL && sendCtx->fp != NULL) { + /* If it is an empty file, do not read. */ + if (*totalFileSz != 0) { + ret = (word32)WFREAD(ssh->fs, buf, 1, bufSz, + sendCtx->fp); + if (ret == 0) { /* handle unexpected case */ + ret = WS_EOF; + } } + } else { + WLOG(WS_LOG_ERROR, + "scp: error extracting file name, abort"); + ret = WS_SCP_ABORT; } - } else { - WLOG(WS_LOG_ERROR, "scp: error extracting file name, abort"); - ret = WS_SCP_ABORT; } /* keep fp open if no errors and transfer will continue */ From 7d6fbcf77073d63e91fa79d1309357a8fe373358 Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Thu, 23 May 2024 13:57:23 -0600 Subject: [PATCH 2/2] add test case --- scripts/scp.test | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scripts/scp.test b/scripts/scp.test index 093db6845..e2104a7dd 100755 --- a/scripts/scp.test +++ b/scripts/scp.test @@ -133,6 +133,21 @@ else exit 1 fi +echo "Test of sending a file that does not exist" +touch $PWD/scripts/empty +./examples/echoserver/echoserver -1 -R $ready_file & +server_pid=$! +create_port +./examples/scpclient/wolfscp -u jill -P upthehill -p $port -L $PWD/does-not-exist:$PWD/empty +RESULT=$? +remove_ready_file + +if test $RESULT -eq 0; then + echo -e "\n\nshould fail out sending a file that does not exist" + do_cleanup + exit 1 +fi + echo -e "\nALL Tests Passed" exit 0