Skip to content

Commit

Permalink
Merge pull request #765 from JacobBarthelmeh/scp
Browse files Browse the repository at this point in the history
use dynamic buffer for SCP base path
  • Loading branch information
dgarske authored Jan 31, 2025
2 parents 86499a5 + 9c1f289 commit a267687
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
10 changes: 5 additions & 5 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1163,11 +1163,11 @@ void SshResourceFree(WOLFSSH* ssh, void* heap)
ssh->scpRecvMsg = NULL;
ssh->scpRecvMsgSz = 0;
}
#ifdef WOLFSSL_NUCLEUS
WFREE(ssh->scpBasePathDynamic, heap, DYNTYPE_BUFFER);
ssh->scpBasePathDynamic = NULL;
ssh->scpBasePathSz = 0;
#endif
if (ssh->scpBasePathDynamic) {
WFREE(ssh->scpBasePathDynamic, heap, DYNTYPE_BUFFER);
ssh->scpBasePathDynamic = NULL;
ssh->scpBasePathSz = 0;
}
#endif
#ifdef WOLFSSH_SFTP
if (ssh->sftpDefaultPath) {
Expand Down
31 changes: 15 additions & 16 deletions src/wolfscp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1260,47 +1260,46 @@ int ParseScpCommand(WOLFSSH* ssh)

case 't':
ssh->scpDirection = WOLFSSH_SCP_TO;
#ifdef WOLFSSL_NUCLEUS
ssh->scpBasePathSz = cmdSz + WOLFSSH_MAX_FILENAME;
ssh->scpBasePathDynamic = (char*)WMALLOC(
ssh->scpBasePathSz,
ssh->ctx->heap, DYNTYPE_BUFFER);
#endif
if (ssh->scpBasePathDynamic == NULL) {
return WS_MEMORY_E;
}
WMEMSET(ssh->scpBasePathDynamic, 0, ssh->scpBasePathSz);
if (idx + 2 < cmdSz) {
/* skip space */
idx += 2;
#ifdef WOLFSSL_NUCLEUS
ssh->scpBasePath = ssh->scpBasePathDynamic;
WMEMCPY(ssh->scpBasePathDynamic, cmd + idx, cmdSz);
#else
ssh->scpBasePath = cmd + idx;
#endif
WMEMCPY(ssh->scpBasePathDynamic, cmd + idx,
cmdSz - idx);
ret = ParseBasePathHelper(ssh, cmdSz);
if (ret == WS_SUCCESS &&
wolfSSH_CleanPath(ssh, (char*)ssh->scpBasePath) < 0)
wolfSSH_CleanPath(ssh,
ssh->scpBasePathDynamic) < 0)
ret = WS_FATAL_ERROR;
}
break;

case 'f':
ssh->scpDirection = WOLFSSH_SCP_FROM;
#ifdef WOLFSSL_NUCLEUS
ssh->scpBasePathSz = cmdSz + WOLFSSH_MAX_FILENAME;
ssh->scpBasePathDynamic = (char*)WMALLOC(
ssh->scpBasePathSz,
ssh->ctx->heap, DYNTYPE_BUFFER);
#endif
if (ssh->scpBasePathDynamic == NULL) {
return WS_MEMORY_E;
}
WMEMSET(ssh->scpBasePathDynamic, 0, ssh->scpBasePathSz);
if (idx + 2 < cmdSz) {
/* skip space */
idx += 2;
#ifdef WOLFSSL_NUCLEUS
ssh->scpBasePath = ssh->scpBasePathDynamic;
WMEMCPY(ssh->scpBasePathDynamic, cmd + idx, cmdSz);
#else
ssh->scpBasePath = cmd + idx;
#endif
WMEMCPY(ssh->scpBasePathDynamic, cmd + idx,
cmdSz - idx);
if (wolfSSH_CleanPath(ssh,
(char*)ssh->scpBasePath) < 0)
ssh->scpBasePathDynamic) < 0)
ret = WS_FATAL_ERROR;
}
break;
Expand Down
2 changes: 0 additions & 2 deletions wolfssh/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -721,11 +721,9 @@ struct WOLFSSH {
char* scpRecvMsg; /* reading up to newline delimiter */
int scpRecvMsgSz; /* current size of scp recv message */
const char* scpBasePath; /* base path, ptr into channelList->command */
#ifdef WOLFSSL_NUCLEUS
/* alter base path instead of using chdir */
char* scpBasePathDynamic; /* dynamic base path */
word32 scpBasePathSz;
#endif
byte scpIsRecursive; /* recursive transfer requested */
byte scpRequestType; /* directory or single file */
byte scpMsgType;
Expand Down

0 comments on commit a267687

Please sign in to comment.