Skip to content

Commit

Permalink
Merge pull request #700 from JacobBarthelmeh/scp
Browse files Browse the repository at this point in the history
error out when trying to send non existent local files
  • Loading branch information
dgarske authored May 29, 2024
2 parents 11f0b22 + 7d6fbcf commit 914f984
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
15 changes: 15 additions & 0 deletions scripts/scp.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 15 additions & 10 deletions src/wolfscp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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 */
Expand Down

0 comments on commit 914f984

Please sign in to comment.