Skip to content

Commit 2be99a2

Browse files
committed
SFTP List
Fixes listing the contents of C:\ on Windows when running the wolfSFTP server. (ZD14607) 1. Change RecvOpenDir to look up the directory the way SFTPNAME_readdir. 2. Removed the calls to CleanPath in RecvOpenDir and SFTPNAME_readdir as it was adding backslashes to the dirName.
1 parent cace79e commit 2be99a2

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/wolfsftp.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,6 +2275,7 @@ int wolfSSH_SFTP_RecvOpenDir(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
22752275
byte* out = NULL;
22762276
word32 id[2];
22772277
byte idFlat[sizeof(word32) * 2];
2278+
char name[MAX_PATH];
22782279

22792280
if (ssh == NULL) {
22802281
return WS_BAD_ARGUMENT;
@@ -2301,13 +2302,16 @@ int wolfSSH_SFTP_RecvOpenDir(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
23012302
}
23022303
WMEMCPY(dirName, data + idx, sz);
23032304
dirName[sz] = '\0';
2304-
if (wolfSSH_CleanPath(ssh, dirName) < 0) {
2305-
WFREE(dirName, ssh->ctx->heap, DYNTYPE_BUFFER);
2305+
2306+
if (sz > MAX_PATH - 2) {
2307+
WLOG(WS_LOG_SFTP, "Path name is too long.");
23062308
return WS_FATAL_ERROR;
23072309
}
2310+
WSTRNCPY(name, dirName, MAX_PATH);
2311+
WSTRNCAT(name, "/*", MAX_PATH);
23082312

2309-
/* get directory handle */
2310-
findHandle = (HANDLE)WS_FindFirstFileA(dirName,
2313+
/* get directory handle - see if directory exists */
2314+
findHandle = (HANDLE)WS_FindFirstFileA(name,
23112315
realName, sizeof(realName), &isDir, ssh->ctx->heap);
23122316
if (findHandle == INVALID_HANDLE_VALUE || !isDir) {
23132317

@@ -2321,7 +2325,8 @@ int wolfSSH_SFTP_RecvOpenDir(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
23212325
}
23222326
ret = WS_BAD_FILE_E;
23232327
}
2324-
FindClose(findHandle);
2328+
if (findHandle != NULL && findHandle != INVALID_HANDLE_VALUE)
2329+
FindClose(findHandle);
23252330

23262331
(void)reqId;
23272332

@@ -2707,12 +2712,12 @@ static int wolfSSH_SFTPNAME_readdir(WOLFSSH* ssh, WDIR* dir, WS_SFTPNAME* out,
27072712
char name[MAX_PATH];
27082713
word32 nameLen = (word32)WSTRLEN(dirName);
27092714

2710-
if (nameLen > MAX_PATH - 3) {
2715+
if (nameLen > MAX_PATH - 2) {
27112716
WLOG(WS_LOG_SFTP, "Path name is too long.");
27122717
return WS_FATAL_ERROR;
27132718
}
27142719
WSTRNCPY(name, dirName, MAX_PATH);
2715-
WSTRNCAT(name, "\\*", MAX_PATH);
2720+
WSTRNCAT(name, "/*", MAX_PATH);
27162721

27172722
findHandle = (HANDLE)WS_FindFirstFileA(name,
27182723
realFileName, sizeof(realFileName), NULL, ssh->ctx->heap);
@@ -2761,11 +2766,6 @@ static int wolfSSH_SFTPNAME_readdir(WOLFSSH* ssh, WDIR* dir, WS_SFTPNAME* out,
27612766
}
27622767
WSTRNCAT(buf, out->fName, bufSz + 1);
27632768

2764-
if (wolfSSH_CleanPath(ssh, buf) < 0) {
2765-
WFREE(buf, out->heap, DYNTYPE_SFTP);
2766-
return WS_FATAL_ERROR;
2767-
}
2768-
27692769
if (SFTP_GetAttributes(ssh->fs, buf, &out->atrb, 0, ssh->ctx->heap)
27702770
!= WS_SUCCESS) {
27712771
WLOG(WS_LOG_SFTP, "Unable to get attribute values for %s",

0 commit comments

Comments
 (0)