From c033c6e97997b738b6cdb97446d7845b2933ed9c Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Fri, 30 Nov 2018 16:58:48 -0700 Subject: [PATCH] use a dynamic buffer for SCP base path with Nucleus port --- src/internal.c | 5 +++++ src/wolfscp.c | 22 ++++++++++++++++++++++ wolfssh/internal.h | 5 +++++ 3 files changed, 32 insertions(+) diff --git a/src/internal.c b/src/internal.c index 3f29dc9..887dc81 100644 --- a/src/internal.c +++ b/src/internal.c @@ -527,6 +527,11 @@ void SshResourceFree(WOLFSSH* ssh, void* heap) ssh->scpFileName = NULL; ssh->scpFileNameSz = 0; } +#ifdef WOLFSSL_NUCLEUS + WFREE(ssh->scpBasePathDynamic, ssh->ctx->heap, DYNTYPE_BUFFER); + ssh->scpBasePathDynamic = NULL; + ssh->scpBasePathSz = 0; +#endif #endif } diff --git a/src/wolfscp.c b/src/wolfscp.c index c7c6c7a..7c69060 100644 --- a/src/wolfscp.c +++ b/src/wolfscp.c @@ -1183,10 +1183,21 @@ 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 (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 clean_path((char*)ssh->scpBasePath); } ret = ParseBasePathHelper(ssh, cmdSz); @@ -1194,10 +1205,21 @@ int ParseScpCommand(WOLFSSH* ssh) 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 (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 clean_path((char*)ssh->scpBasePath); } break; diff --git a/wolfssh/internal.h b/wolfssh/internal.h index e841aec..5927264 100644 --- a/wolfssh/internal.h +++ b/wolfssh/internal.h @@ -294,6 +294,11 @@ struct WOLFSSH { char* scpConfirmMsg; /* dynamic, confirm message string */ word32 scpConfirmMsgSz; /* length of confirmMsg, not including \0 */ 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;