Skip to content

Commit 53dd6ad

Browse files
Run threaded api-test SFTP/SCP tests on Windows
1 parent cc5311a commit 53dd6ad

7 files changed

Lines changed: 128 additions & 52 deletions

File tree

‎.github/workflows/windows-check.yml‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,13 @@ jobs:
139139
run: nuget restore ${{env.WOLFSSL_SOLUTION_FILE_PATH}}
140140

141141
# These env paths already include the wolfssh/ and wolfssl/ checkout
142-
# prefixes, so they must run from the workspace root (as the build job does).
143-
- name: updated user_settings.h for sshd and x509
144-
run: cp ${{env.USER_SETTINGS_H_NEW}} ${{env.USER_SETTINGS_H}}
145-
146-
- name: replace wolfSSL user_settings.h with wolfSSH user_settings.h
147-
run: get-content ${{env.USER_SETTINGS_H_NEW}} | %{$_ -replace "if 0","if 1"}
142+
# prefixes, so this runs from the default working directory, the workspace
143+
# root.
144+
- name: Enable wolfSSH options (sshd, sftp, x509) in user_settings.h
145+
shell: bash
146+
run: |
147+
sed -i 's/#if 0/#if 1/g' ${{env.USER_SETTINGS_H_NEW}}
148+
cp ${{env.USER_SETTINGS_H_NEW}} ${{env.USER_SETTINGS_H}}
148149
149150
# WholeProgramOptimization=false disables /GL so the v142-independent objects
150151
# link without a cross-version code-generation requirement (C1047).

‎examples/echoserver/echoserver.c‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2249,6 +2249,11 @@ static int LoadPasswdList(StrList* strList, PwMapList* mapList)
22492249
int count = 0;
22502250

22512251
while (strList) {
2252+
if (WSTRLEN(strList->str) >= sizeof names - 1) {
2253+
fprintf(stderr, "Ignoring over-long entry: %.32s\n", strList->str);
2254+
strList = strList->next;
2255+
continue;
2256+
}
22522257
WSTRNCPY(names, strList->str, sizeof names - 1);
22532258
passwd = WSTRCHR(names, ':');
22542259
if (passwd != NULL) {
@@ -2278,6 +2283,11 @@ static int LoadKeyboardList(StrList* strList, PwMapList* mapList,
22782283
int count = 0;
22792284

22802285
while (strList) {
2286+
if (WSTRLEN(strList->str) >= sizeof names - 1) {
2287+
fprintf(stderr, "Ignoring over-long entry: %.32s\n", strList->str);
2288+
strList = strList->next;
2289+
continue;
2290+
}
22812291
WSTRNCPY(names, strList->str, sizeof names - 1);
22822292
passwd = WSTRCHR(names, ':');
22832293
if (passwd != NULL) {
@@ -2314,6 +2324,11 @@ static int LoadPubKeyList(StrList* strList, int format, PwMapList* mapList)
23142324
buf = NULL;
23152325
bufSz = 0;
23162326

2327+
if (WSTRLEN(strList->str) >= sizeof names - 1) {
2328+
fprintf(stderr, "Ignoring over-long entry: %.32s\n", strList->str);
2329+
strList = strList->next;
2330+
continue;
2331+
}
23172332
WSTRNCPY(names, strList->str, sizeof names - 1);
23182333
fileName = WSTRCHR(names, ':');
23192334
if (fileName != NULL) {
@@ -2834,6 +2849,12 @@ static INLINE void SignalTcpReady(tcp_ready* ready, word16 port)
28342849
ready->port = port;
28352850
pthread_cond_signal(&ready->cond);
28362851
pthread_mutex_unlock(&ready->mutex);
2852+
#elif defined(USE_WINDOWS_API) && defined(NO_MAIN_DRIVER) && \
2853+
!defined(SINGLE_THREADED)
2854+
ready->ready = 1;
2855+
ready->port = port;
2856+
/* SetEvent is a full barrier; this one-shot signal needs no lock */
2857+
SetEvent(ready->readyEvent);
28372858
#else
28382859
WOLFSSH_UNUSED(ready);
28392860
WOLFSSH_UNUSED(port);
@@ -2979,7 +3000,7 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
29793000
}
29803001
else {
29813002
port = (word16)atoi(myoptarg);
2982-
#if !defined(NO_MAIN_DRIVER) || defined(USE_WINDOWS_API)
3003+
#if !defined(NO_MAIN_DRIVER)
29833004
if (port == 0) {
29843005
ES_ERROR("port number cannot be 0");
29853006
}

‎examples/sftpclient/sftpclient.c‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ static void myStatusCb(WOLFSSH* sshIn, word32* bytes, char* name)
156156
static word32 lastOutputTime = 0;
157157
static word32 lastPrintedBytes[2] = {0, 0};
158158
word32 elapsedTime;
159+
word32 nameSz;
159160
#endif
160161
char buf[80];
161162
word64 longBytes = ((word64)bytes[1] << 32) | bytes[0];
@@ -181,8 +182,13 @@ static void myStatusCb(WOLFSSH* sshIn, word32* bytes, char* name)
181182
lastOutputTime = 0; /* Reset timer for new file transfer */
182183
lastPrintedBytes[0] = 0;
183184
lastPrintedBytes[1] = 0;
184-
WMEMSET(currentFile, 0, WOLFSSH_MAX_FILENAME);
185-
WSTRNCPY(currentFile, name, WOLFSSH_MAX_FILENAME);
185+
WMEMSET(currentFile, 0, sizeof(currentFile));
186+
nameSz = (word32)WSTRLEN(name);
187+
/* clamp over-long names: returning would leave currentFile empty
188+
* and suppress progress output for the rest of the transfer */
189+
if (nameSz >= sizeof(currentFile))
190+
nameSz = (word32)sizeof(currentFile) - 1;
191+
WMEMCPY(currentFile, name, nameSz);
186192
}
187193
elapsedTime = currentTime - startTime;
188194
WSNPRINTF(buf, sizeof(buf), "Processed %8llu\t bytes in %d seconds\r",
@@ -191,7 +197,7 @@ static void myStatusCb(WOLFSSH* sshIn, word32* bytes, char* name)
191197
if (elapsedTime > TIMEOUT_VALUE) {
192198
WSNPRINTF(buf, sizeof(buf), "\nProcess timed out at %d seconds, "
193199
"stopping\r", elapsedTime);
194-
WMEMSET(currentFile, 0, WOLFSSH_MAX_FILENAME);
200+
WMEMSET(currentFile, 0, sizeof(currentFile));
195201
wolfSSH_SFTP_Interrupt(ssh);
196202
}
197203
#endif
@@ -667,7 +673,7 @@ static int doCmds(func_args* args)
667673
ret == WS_CHAN_RXD || ret == WS_REKEYING);
668674

669675
#ifndef WOLFSSH_NO_TIMESTAMP
670-
WMEMSET(currentFile, 0, WOLFSSH_MAX_FILENAME);
676+
WMEMSET(currentFile, 0, sizeof(currentFile));
671677
#endif
672678

673679
if (ret != WS_SUCCESS) {
@@ -778,7 +784,7 @@ static int doCmds(func_args* args)
778784
ret == WS_CHAN_RXD || ret == WS_REKEYING);
779785

780786
#ifndef WOLFSSH_NO_TIMESTAMP
781-
WMEMSET(currentFile, 0, WOLFSSH_MAX_FILENAME);
787+
WMEMSET(currentFile, 0, sizeof(currentFile));
782788
#endif
783789

784790
if (ret != WS_SUCCESS) {
@@ -1445,6 +1451,7 @@ static int doAutopilot(int cmd, char* local, char* remote)
14451451
int ret = WS_SUCCESS;
14461452
char fullpath[128] = ".";
14471453
WS_SFTPNAME* name = NULL;
1454+
word32 remoteSz;
14481455
byte remoteAbsPath = 0;
14491456

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

14631470
if (remoteAbsPath) {
14641471
/* use remote absolute path if provided */
1472+
remoteSz = (word32)WSTRLEN(remote);
1473+
if (remoteSz >= sizeof(fullpath))
1474+
return WS_BUFFER_E;
14651475
WMEMSET(fullpath, 0, sizeof(fullpath));
1466-
WSTRNCPY(fullpath, remote, sizeof(fullpath) - 1);
1476+
WMEMCPY(fullpath, remote, remoteSz + 1);
14671477
}
14681478
else {
14691479
err = doBuildRemotePath(remote, fullpath, sizeof(fullpath), &name);

‎src/wolfscp.c‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,20 +1952,27 @@ int wolfSSH_SCP_connect(WOLFSSH* ssh, byte* cmd)
19521952
}
19531953

19541954

1955+
/* Shared format so the size probe and the write cannot drift. */
1956+
#define SCP_CMD_FMT "scp -%c %s"
1957+
19551958
static char* MakeScpCmd(const char* name, char dir, void* heap)
19561959
{
19571960
char* cmd;
19581961
int sz;
19591962

1960-
sz = WSNPRINTF(NULL, 0, "scp -%c %s", dir, name) + 1;
1963+
#ifdef USE_WINDOWS_API
1964+
sz = WSCPRINTF(SCP_CMD_FMT, dir, name) + 1;
1965+
#else
1966+
sz = WSNPRINTF(NULL, 0, SCP_CMD_FMT, dir, name) + 1;
1967+
#endif
19611968
if (sz <= 0) {
19621969
return NULL;
19631970
}
19641971
cmd = (char*)WMALLOC(sz, heap, DYNTYPE_STRING);
19651972
if (cmd == NULL) {
19661973
return NULL;
19671974
}
1968-
sz = WSNPRINTF(cmd, sz, "scp -%c %s", dir, name);
1975+
sz = WSNPRINTF(cmd, sz, SCP_CMD_FMT, dir, name);
19691976
if (sz <= 0) {
19701977
WFREE(cmd, heap, DYNTYPE_STRING);
19711978
return NULL;
@@ -2712,10 +2719,15 @@ static ScpDir* ScpNewDir(void *fs, const char* path, void* heap)
27122719
int ScpPushDir(void *fs, ScpSendCtx* ctx, const char* path, void* heap)
27132720
{
27142721
ScpDir* entry;
2722+
word32 pathSz;
27152723

27162724
if (ctx == NULL || path == NULL)
27172725
return WS_BAD_ARGUMENT;
27182726

2727+
pathSz = (word32)WSTRLEN(path);
2728+
if (pathSz >= sizeof(ctx->dirName))
2729+
return WS_BUFFER_E;
2730+
27192731
entry = ScpNewDir(fs, path, heap);
27202732
if (entry == NULL) {
27212733
return WS_FATAL_ERROR;
@@ -2729,9 +2741,9 @@ int ScpPushDir(void *fs, ScpSendCtx* ctx, const char* path, void* heap)
27292741
ctx->currentDir = entry;
27302742
}
27312743

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

27362748
return WS_SUCCESS;
27372749
}

0 commit comments

Comments
 (0)