use a dynamic buffer for SCP base path with Nucleus port

pull/121/head
Jacob Barthelmeh 2018-11-30 16:58:48 -07:00
parent 26d9140507
commit c033c6e979
3 changed files with 32 additions and 0 deletions

View File

@ -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
}

View File

@ -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;

View File

@ -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;