Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .github/workflows/windows-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,13 @@ jobs:
run: nuget restore ${{env.WOLFSSL_SOLUTION_FILE_PATH}}

# These env paths already include the wolfssh/ and wolfssl/ checkout
# prefixes, so they must run from the workspace root (as the build job does).
- name: updated user_settings.h for sshd and x509
run: cp ${{env.USER_SETTINGS_H_NEW}} ${{env.USER_SETTINGS_H}}

- name: replace wolfSSL user_settings.h with wolfSSH user_settings.h
run: get-content ${{env.USER_SETTINGS_H_NEW}} | %{$_ -replace "if 0","if 1"}
# prefixes, so this runs from the default working directory, the workspace
# root.
- name: Enable wolfSSH options (sshd, sftp, x509) in user_settings.h
shell: bash
run: |
sed -i 's/#if 0/#if 1/g' ${{env.USER_SETTINGS_H_NEW}}
cp ${{env.USER_SETTINGS_H_NEW}} ${{env.USER_SETTINGS_H}}

# WholeProgramOptimization=false disables /GL so the v142-independent objects
# link without a cross-version code-generation requirement (C1047).
Expand Down
23 changes: 22 additions & 1 deletion examples/echoserver/echoserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -2249,6 +2249,11 @@ static int LoadPasswdList(StrList* strList, PwMapList* mapList)
int count = 0;

while (strList) {
if (WSTRLEN(strList->str) >= sizeof names - 1) {
Comment thread
ejohnstown marked this conversation as resolved.
fprintf(stderr, "Ignoring over-long entry: %.32s\n", strList->str);
strList = strList->next;
continue;
}
WSTRNCPY(names, strList->str, sizeof names - 1);
passwd = WSTRCHR(names, ':');
if (passwd != NULL) {
Expand Down Expand Up @@ -2278,6 +2283,11 @@ static int LoadKeyboardList(StrList* strList, PwMapList* mapList,
int count = 0;

while (strList) {
if (WSTRLEN(strList->str) >= sizeof names - 1) {
fprintf(stderr, "Ignoring over-long entry: %.32s\n", strList->str);
strList = strList->next;
continue;
}
WSTRNCPY(names, strList->str, sizeof names - 1);
passwd = WSTRCHR(names, ':');
if (passwd != NULL) {
Expand Down Expand Up @@ -2314,6 +2324,11 @@ static int LoadPubKeyList(StrList* strList, int format, PwMapList* mapList)
buf = NULL;
bufSz = 0;

if (WSTRLEN(strList->str) >= sizeof names - 1) {
fprintf(stderr, "Ignoring over-long entry: %.32s\n", strList->str);
strList = strList->next;
continue;
}
WSTRNCPY(names, strList->str, sizeof names - 1);
fileName = WSTRCHR(names, ':');
if (fileName != NULL) {
Expand Down Expand Up @@ -2834,6 +2849,12 @@ static INLINE void SignalTcpReady(tcp_ready* ready, word16 port)
ready->port = port;
pthread_cond_signal(&ready->cond);
pthread_mutex_unlock(&ready->mutex);
#elif defined(USE_WINDOWS_API) && defined(NO_MAIN_DRIVER) && \
!defined(SINGLE_THREADED)
ready->ready = 1;
ready->port = port;
/* SetEvent is a full barrier; this one-shot signal needs no lock */
SetEvent(ready->readyEvent);
#else
WOLFSSH_UNUSED(ready);
WOLFSSH_UNUSED(port);
Expand Down Expand Up @@ -2979,7 +3000,7 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
}
else {
port = (word16)atoi(myoptarg);
#if !defined(NO_MAIN_DRIVER) || defined(USE_WINDOWS_API)
#if !defined(NO_MAIN_DRIVER)
if (port == 0) {
ES_ERROR("port number cannot be 0");
}
Expand Down
25 changes: 18 additions & 7 deletions examples/sftpclient/sftpclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ static void myStatusCb(WOLFSSH* sshIn, word32* bytes, char* name)
static word32 lastOutputTime = 0;
static word32 lastPrintedBytes[2] = {0, 0};
word32 elapsedTime;
word32 nameSz;
#endif
char buf[80];
word64 longBytes = ((word64)bytes[1] << 32) | bytes[0];
Expand All @@ -176,13 +177,19 @@ static void myStatusCb(WOLFSSH* sshIn, word32* bytes, char* name)
}
lastPrintedBytes[0] = bytes[0];
lastPrintedBytes[1] = bytes[1];
if (WSTRNCMP(currentFile, name, WSTRLEN(name)) != 0) {
/* clamp over-long names: currentFile holds the truncated prefix, so the
* comparison must use the same bound or every call looks like a new file */
nameSz = (word32)WSTRLEN(name);
if (nameSz >= sizeof(currentFile))
nameSz = (word32)sizeof(currentFile) - 1;
if (WSTRNCMP(currentFile, name, nameSz) != 0 ||
currentFile[nameSz] != '\0') {
startTime = current_time(1);
lastOutputTime = 0; /* Reset timer for new file transfer */
lastPrintedBytes[0] = 0;
lastPrintedBytes[1] = 0;
WMEMSET(currentFile, 0, WOLFSSH_MAX_FILENAME);
WSTRNCPY(currentFile, name, WOLFSSH_MAX_FILENAME);
WMEMSET(currentFile, 0, sizeof(currentFile));
WMEMCPY(currentFile, name, nameSz);
Comment thread
ejohnstown marked this conversation as resolved.
}
Comment thread
ejohnstown marked this conversation as resolved.
elapsedTime = currentTime - startTime;
WSNPRINTF(buf, sizeof(buf), "Processed %8llu\t bytes in %d seconds\r",
Comment thread
ejohnstown marked this conversation as resolved.
Expand All @@ -191,7 +198,7 @@ static void myStatusCb(WOLFSSH* sshIn, word32* bytes, char* name)
if (elapsedTime > TIMEOUT_VALUE) {
WSNPRINTF(buf, sizeof(buf), "\nProcess timed out at %d seconds, "
"stopping\r", elapsedTime);
WMEMSET(currentFile, 0, WOLFSSH_MAX_FILENAME);
WMEMSET(currentFile, 0, sizeof(currentFile));
wolfSSH_SFTP_Interrupt(ssh);
}
#endif
Expand Down Expand Up @@ -667,7 +674,7 @@ static int doCmds(func_args* args)
ret == WS_CHAN_RXD || ret == WS_REKEYING);

#ifndef WOLFSSH_NO_TIMESTAMP
WMEMSET(currentFile, 0, WOLFSSH_MAX_FILENAME);
WMEMSET(currentFile, 0, sizeof(currentFile));
#endif

if (ret != WS_SUCCESS) {
Expand Down Expand Up @@ -778,7 +785,7 @@ static int doCmds(func_args* args)
ret == WS_CHAN_RXD || ret == WS_REKEYING);

#ifndef WOLFSSH_NO_TIMESTAMP
WMEMSET(currentFile, 0, WOLFSSH_MAX_FILENAME);
WMEMSET(currentFile, 0, sizeof(currentFile));
#endif

if (ret != WS_SUCCESS) {
Expand Down Expand Up @@ -1445,6 +1452,7 @@ static int doAutopilot(int cmd, char* local, char* remote)
int ret = WS_SUCCESS;
char fullpath[128] = ".";
WS_SFTPNAME* name = NULL;
word32 remoteSz;
byte remoteAbsPath = 0;

/* check if is absolute path before making it one */
Expand All @@ -1462,8 +1470,11 @@ static int doAutopilot(int cmd, char* local, char* remote)

if (remoteAbsPath) {
/* use remote absolute path if provided */
remoteSz = (word32)WSTRLEN(remote);
if (remoteSz >= sizeof(fullpath))
return WS_BUFFER_E;
WMEMSET(fullpath, 0, sizeof(fullpath));
WSTRNCPY(fullpath, remote, sizeof(fullpath) - 1);
WMEMCPY(fullpath, remote, remoteSz + 1);
}
else {
err = doBuildRemotePath(remote, fullpath, sizeof(fullpath), &name);
Expand Down
37 changes: 32 additions & 5 deletions src/wolfscp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1952,20 +1952,27 @@ int wolfSSH_SCP_connect(WOLFSSH* ssh, byte* cmd)
}


/* Shared format so the size probe and the write cannot drift. */
#define SCP_CMD_FMT "scp -%c %s"

static char* MakeScpCmd(const char* name, char dir, void* heap)
{
char* cmd;
int sz;

sz = WSNPRINTF(NULL, 0, "scp -%c %s", dir, name) + 1;
#ifdef USE_WINDOWS_API
Comment thread
ejohnstown marked this conversation as resolved.
sz = WSCPRINTF(SCP_CMD_FMT, dir, name) + 1;
#else
sz = WSNPRINTF(NULL, 0, SCP_CMD_FMT, dir, name) + 1;
#endif
if (sz <= 0) {
return NULL;
}
cmd = (char*)WMALLOC(sz, heap, DYNTYPE_STRING);
if (cmd == NULL) {
return NULL;
}
sz = WSNPRINTF(cmd, sz, "scp -%c %s", dir, name);
sz = WSNPRINTF(cmd, sz, SCP_CMD_FMT, dir, name);
if (sz <= 0) {
WFREE(cmd, heap, DYNTYPE_STRING);
return NULL;
Expand Down Expand Up @@ -2712,10 +2719,15 @@ static ScpDir* ScpNewDir(void *fs, const char* path, void* heap)
int ScpPushDir(void *fs, ScpSendCtx* ctx, const char* path, void* heap)
{
ScpDir* entry;
word32 pathSz;

if (ctx == NULL || path == NULL)
return WS_BAD_ARGUMENT;

pathSz = (word32)WSTRLEN(path);
Comment thread
ejohnstown marked this conversation as resolved.
Comment thread
ejohnstown marked this conversation as resolved.
if (pathSz >= sizeof(ctx->dirName))
return WS_BUFFER_E;

entry = ScpNewDir(fs, path, heap);
if (entry == NULL) {
return WS_FATAL_ERROR;
Expand All @@ -2729,13 +2741,28 @@ int ScpPushDir(void *fs, ScpSendCtx* ctx, const char* path, void* heap)
ctx->currentDir = entry;
}

/* append directory name to ctx->dirName */
WSTRNCPY(ctx->dirName, path, DEFAULT_SCP_FILE_NAME_SZ-1);
ctx->dirName[DEFAULT_SCP_FILE_NAME_SZ-1] = '\0';
/* append directory name to ctx->dirName, terminator included; the guard
* above bounds pathSz so the copy always fits */
WMEMCPY(ctx->dirName, path, pathSz + 1);

return WS_SUCCESS;
}

#ifdef WOLFSSH_TEST_INTERNAL
int wolfSSH_TestScpPushDir(const char* path)
{
ScpSendCtx ctx;
int ret;

WMEMSET(&ctx, 0, sizeof(ctx));
ret = ScpPushDir(NULL, &ctx, path, NULL);
if (ret == WS_SUCCESS)
ScpSendCtxFreeDirs(NULL, &ctx, NULL);

return ret;
}
#endif /* WOLFSSH_TEST_INTERNAL */

/* Remove top ScpDir from directory stack, remove dir from ctx->dirName */
int ScpPopDir(void *fs, ScpSendCtx* ctx, void* heap)
{
Expand Down
Loading
Loading