From 82032bddfe539ed3cb0c17524ef88e2423c646c1 Mon Sep 17 00:00:00 2001 From: Hideki Miyazaki Date: Fri, 4 Sep 2026 16:46:30 -0400 Subject: [PATCH] tests: Stop TestKnownHostsLastEntry depending on WMKDIR A local run with ./configure --enable-smallstack (no --enable-sftp) showed WMKDIR as an implicit, undeclared function under MinGW. wolfssh/port.h only defines WMKDIR when WOLFSSH_SFTP, WOLFSSH_SCP, or WOLFSSH_SSHD is enabled, but TestKnownHostsLastEntry itself is gated on WOLFSSL_BASE64_ENCODE alone, so it compiles in configurations where none of those three are on and WMKDIR does not exist. Add a small TEST_MKDIR macro next to the existing TEST_SETENV and TEST_UNSETENV ones, backed directly by _mkdir() under USE_WINDOWS_API and mkdir() otherwise, and use it in place of WMKDIR. The Windows branch needs direct.h for _mkdir's declaration; include it next to the existing _WIN32 guard around arpa/inet.h at the top of the file. Verified with the MinGW cross compiler both with WOLFSSH_SFTP defined and without, and confirmed a plain Linux build configured with --enable-smallstack (no --enable-sftp) still passes tests/regress.test and tests/unit.test. --- tests/regress.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/regress.c b/tests/regress.c index f0320391..2fdbdc12 100644 --- a/tests/regress.c +++ b/tests/regress.c @@ -34,6 +34,8 @@ #include #ifndef _WIN32 #include +#else + #include #endif #include #include @@ -13366,13 +13368,18 @@ static int KnownHostsCheckCapture(const byte* pubKey, word32 pubKeySz, /* setenv()/unsetenv() are POSIX and have no MSVCRT equivalent; _putenv_s() * matches their (name, value) shape and success/failure return closely - * enough for this test's own HOME juggling. */ + * enough for this test's own HOME juggling. WMKDIR is not an option here: + * it is only defined when wolfssh/port.h is built with SFTP, SCP, or sshd + * support, and this test compiles whenever WOLFSSL_BASE64_ENCODE is set, + * independent of those. */ #ifdef USE_WINDOWS_API #define TEST_SETENV(n,v) _putenv_s((n), (v)) #define TEST_UNSETENV(n) _putenv_s((n), "") + #define TEST_MKDIR(p,m) _mkdir((p)) #else #define TEST_SETENV(n,v) setenv((n), (v), 1) #define TEST_UNSETENV(n) unsetenv((n)) + #define TEST_MKDIR(p,m) mkdir((p), (m)) #endif /* known_hosts is a text file and POSIX lets its last line end without a @@ -13439,8 +13446,8 @@ static void TestKnownHostsLastEntry(void) (void)rmdir(homeDir); /* Use a single flag to avoid duplicate errors below. */ - ready = (WMKDIR(NULL, homeDir, 0700) == 0) - && (WMKDIR(NULL, sshDir, 0700) == 0) + ready = (TEST_MKDIR(homeDir, 0700) == 0) + && (TEST_MKDIR(sshDir, 0700) == 0) && (TEST_SETENV("HOME", homeDir) == 0); AssertTrue(ready);