Release v1.4.18: Release Testing Fixes (Windows)

1. For the ASCII and Wide versions of types and functions, make sure
   the wolfSSHd is being consistent using them.
2. In SFTP, use WSOCKETCLOSE to close the socket. Use the correct type
   for the socket.
3. Add parens around part of a ternary operator check to clear up some
   ambiguous order of operations.
4. Add a variable initializer for a COORD structure.
5. Add parameter checks to the Base16_Decode function.
6. Fix a double-freed handle.
7. Clean up a bunch of build warnings.
pull/726/head
John Safranek 2024-07-18 16:37:49 -07:00
parent dc2065719f
commit 1a6225671b
5 changed files with 44 additions and 35 deletions

View File

@ -151,6 +151,7 @@ static void SyslogCb(enum wolfSSH_LogLevel level, const char *const msgStr)
#ifdef _WIN32 #ifdef _WIN32
static void ServiceDebugCb(enum wolfSSH_LogLevel level, const char* const msgStr) static void ServiceDebugCb(enum wolfSSH_LogLevel level, const char* const msgStr)
#ifdef UNICODE
{ {
WCHAR* wc; WCHAR* wc;
size_t szWord = WSTRLEN(msgStr) + 3; /* + 3 for null terminator and new size_t szWord = WSTRLEN(msgStr) + 3; /* + 3 for null terminator and new
@ -170,7 +171,13 @@ static void ServiceDebugCb(enum wolfSSH_LogLevel level, const char* const msgStr
} }
WOLFSSH_UNUSED(level); WOLFSSH_UNUSED(level);
} }
#else
{
OutputDebugString(msgStr);
WOLFSSH_UNUSED(level);
}
#endif #endif
#endif /* _WIN32 */
static void ShowUsage(void) static void ShowUsage(void)
{ {
@ -674,7 +681,6 @@ static int SFTP_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
} }
if (ret == WS_SUCCESS) { if (ret == WS_SUCCESS) {
r[rSz] = '\0';
wolfSSH_Log(WS_LOG_INFO, wolfSSH_Log(WS_LOG_INFO,
"[SSHD] Using directory %s for SFTP connection", r); "[SSHD] Using directory %s for SFTP connection", r);
if (wolfSSH_SFTP_SetDefaultPath(ssh, r) != WS_SUCCESS) { if (wolfSSH_SFTP_SetDefaultPath(ssh, r) != WS_SUCCESS) {
@ -832,7 +838,6 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
/* @TODO check for conpty support LoadLibrary()and GetProcAddress(). */ /* @TODO check for conpty support LoadLibrary()and GetProcAddress(). */
if (forcedCmd != NULL && WSTRCMP(forcedCmd, "internal-sftp") == 0) { if (forcedCmd != NULL && WSTRCMP(forcedCmd, "internal-sftp") == 0) {
wolfSSH_Log(WS_LOG_ERROR, wolfSSH_Log(WS_LOG_ERROR,
"[SSHD] Only SFTP connections allowed for user " "[SSHD] Only SFTP connections allowed for user "
@ -912,6 +917,7 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
if (ret == WS_SUCCESS) { if (ret == WS_SUCCESS) {
SECURITY_ATTRIBUTES saAttr; SECURITY_ATTRIBUTES saAttr;
ZeroMemory(&saAttr, sizeof(saAttr));
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
saAttr.bInheritHandle = TRUE; saAttr.bInheritHandle = TRUE;
saAttr.lpSecurityDescriptor = NULL; saAttr.lpSecurityDescriptor = NULL;
@ -926,28 +932,30 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
} }
if (ret == WS_SUCCESS) { if (ret == WS_SUCCESS) {
STARTUPINFO si; STARTUPINFOW si;
PCWSTR conCmd = L"wolfsshd.exe -r "; PCWSTR conCmd = L"wolfsshd.exe -r ";
PWSTR conCmdPtr; PWSTR conCmdPtr;
int conCmdSz; size_t conCmdSz;
SetHandleInformation(ptyIn, HANDLE_FLAG_INHERIT, 0); SetHandleInformation(ptyIn, HANDLE_FLAG_INHERIT, 0);
SetHandleInformation(ptyOut, HANDLE_FLAG_INHERIT, 0); SetHandleInformation(ptyOut, HANDLE_FLAG_INHERIT, 0);
wolfSSH_SetTerminalResizeCtx(ssh, (void*)&ptyIn); wolfSSH_SetTerminalResizeCtx(ssh, (void*)&ptyIn);
conCmdSz = (int)(wcslen(conCmd) + cmdSz + 2); /* +1 for terminator */ conCmdSz = wcslen(conCmd) + cmdSz + 3;
conCmdPtr = (PWSTR)WMALLOC(sizeof(wchar_t) * conCmdSz, NULL, DYNTYPE_SSHD); /* +1 for terminator, +2 for quotes */
conCmdPtr = (PWSTR)WMALLOC(sizeof(wchar_t) * conCmdSz,
NULL, DYNTYPE_SSHD);
if (conCmdPtr == NULL) { if (conCmdPtr == NULL) {
ret = WS_MEMORY_E; ret = WS_MEMORY_E;
} }
else { else {
memset(conCmdPtr, 0, conCmdSz * sizeof(wchar_t)); _snwprintf_s(conCmdPtr, conCmdSz, conCmdSz,
_snwprintf(conCmdPtr, conCmdSz * sizeof(wchar_t), L"wolfsshd.exe -r \"%s\"", cmd); L"wolfsshd.exe -r \"%s\"", cmd);
} }
ZeroMemory(&si, sizeof(STARTUPINFO)); ZeroMemory(&si, sizeof(si));
si.cb = sizeof(STARTUPINFO); si.cb = sizeof(si);
si.hStdInput = cnslIn; si.hStdInput = cnslIn;
si.hStdOutput = cnslOut; si.hStdOutput = cnslOut;
@ -967,7 +975,6 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
CloseHandle(cnslOut); CloseHandle(cnslOut);
WFREE(conCmdPtr, NULL, DYNTYPE_SSHD); WFREE(conCmdPtr, NULL, DYNTYPE_SSHD);
CloseHandle(processInfo.hThread);
} }
if (ret == WS_SUCCESS) { if (ret == WS_SUCCESS) {
@ -2374,7 +2381,7 @@ static int StartSSHD(int argc, char** argv)
wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Issue updating service status"); wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Issue updating service status");
} }
} }
if (ret == WS_SUCCESS) {
/* Create a stop event to watch on */ /* Create a stop event to watch on */
serviceStop = CreateEvent(NULL, TRUE, FALSE, NULL); serviceStop = CreateEvent(NULL, TRUE, FALSE, NULL);
if (serviceStop == NULL) { if (serviceStop == NULL) {
@ -2388,7 +2395,7 @@ static int StartSSHD(int argc, char** argv)
} }
return; return;
} }
}
if (cmdArgs != NULL) { if (cmdArgs != NULL) {
LocalFree(cmdArgs); LocalFree(cmdArgs);
} }
@ -2550,8 +2557,8 @@ static int SetupConsole(char* inCmd)
HANDLE sOut; HANDLE sOut;
HANDLE sIn; HANDLE sIn;
HPCON pCon = 0; HPCON pCon = 0;
COORD cord; COORD cord = { 80,24 }; /* Default to 80x24. Updated later. */
STARTUPINFOEX ext; STARTUPINFOEXW ext;
int ret = WS_SUCCESS; int ret = WS_SUCCESS;
PWSTR cmd = NULL; PWSTR cmd = NULL;
size_t cmdSz = 0; size_t cmdSz = 0;
@ -2564,10 +2571,6 @@ static int SetupConsole(char* inCmd)
return -1; return -1;
} }
/* defautl 80x24 with setup, screen size will get set by VT command after started */
cord.X = 80;
cord.Y = 24;
sIn = GetStdHandle(STD_INPUT_HANDLE); sIn = GetStdHandle(STD_INPUT_HANDLE);
if (WSTRCMP(shellCmd, inCmd) != 0) { if (WSTRCMP(shellCmd, inCmd) != 0) {

View File

@ -4538,9 +4538,9 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
atr->flags |= WOLFSSH_FILEATRB_PERM; atr->flags |= WOLFSSH_FILEATRB_PERM;
atr->per = 0555 | atr->per = 0555 |
(stats.dwFileAttributes | FILE_ATTRIBUTE_READONLY ? 0 : 0200); ((stats.dwFileAttributes | FILE_ATTRIBUTE_READONLY) ? 0 : 0200);
atr->per |= (stats.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? 0x4000: atr->per |= ((stats.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
FILEATRB_PER_FILE; ? FILEATRB_PER_DIR : FILEATRB_PER_FILE);
#if 0 #if 0
/* @TODO handle the constellation of possible Windows FILETIMEs */ /* @TODO handle the constellation of possible Windows FILETIMEs */

View File

@ -28,6 +28,7 @@
#include <wolfssl/options.h> #include <wolfssl/options.h>
#endif #endif
#include <wolfssl/wolfcrypt/wc_port.h> #include <wolfssl/wolfcrypt/wc_port.h>
#include <wolfssh/port.h>
#include <stdio.h> #include <stdio.h>
#include <wolfssh/ssh.h> #include <wolfssh/ssh.h>
@ -955,7 +956,7 @@ static void test_wolfSSH_SFTP_SendReadPacket(void)
func_args ser; func_args ser;
tcp_ready ready; tcp_ready ready;
int argsCount; int argsCount;
int clientFd; WS_SOCKET_T clientFd;
const char* args[10]; const char* args[10];
WOLFSSH_CTX* ctx = NULL; WOLFSSH_CTX* ctx = NULL;
@ -1066,7 +1067,7 @@ static void test_wolfSSH_SFTP_SendReadPacket(void)
/* close client socket down */ /* close client socket down */
clientFd = wolfSSH_get_fd(ssh); clientFd = wolfSSH_get_fd(ssh);
close(clientFd); WCLOSESOCKET(clientFd);
wolfSSH_free(ssh); wolfSSH_free(ssh);
wolfSSH_CTX_free(ctx); wolfSSH_CTX_free(ctx);

View File

@ -186,7 +186,9 @@ int wolfSSH_SftpTest(int flag)
int argsCount; int argsCount;
const char* args[10]; const char* args[10];
#ifndef USE_WINDOWS_API
char portNumber[8]; char portNumber[8];
#endif
THREAD_TYPE serThread; THREAD_TYPE serThread;

View File

@ -221,7 +221,7 @@
#ifdef USE_WINDOWS_API #ifdef USE_WINDOWS_API
#define WCLOSESOCKET(s) closesocket(s) #define WCLOSESOCKET(s) closesocket(s)
#define WSTARTTCP() do { WSADATA wsd; WSAStartup(0x0002, &wsd); } while(0) #define WSTARTTCP() do { WSADATA wsd; (void)WSAStartup(0x0002, &wsd); } while(0)
#elif defined(MICROCHIP_TCPIP) || defined(MICROCHIP_MPLAB_HARMONY) #elif defined(MICROCHIP_TCPIP) || defined(MICROCHIP_MPLAB_HARMONY)
#ifdef MICROCHIP_MPLAB_HARMONY #ifdef MICROCHIP_MPLAB_HARMONY
#define WCLOSESOCKET(s) TCPIP_TCP_Close((s)) #define WCLOSESOCKET(s) TCPIP_TCP_Close((s))
@ -1136,6 +1136,9 @@ static int Base16_Decode(const byte* in, word32 inLen,
word32 inIdx = 0; word32 inIdx = 0;
word32 outIdx = 0; word32 outIdx = 0;
if (in == NULL || out == NULL || outLen == NULL)
return WS_BAD_ARGUMENT;
if (inLen == 1 && *outLen && in) { if (inLen == 1 && *outLen && in) {
byte b = in[inIdx] - 0x30; /* 0 starts at 0x30 */ byte b = in[inIdx] - 0x30; /* 0 starts at 0x30 */