From 108e55a3c5f064681dcbf02400f0fdb88e69e813 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Sun, 15 Feb 2026 04:24:46 +0300 Subject: [PATCH] Fix remaining Windows test build issues - Remove sys/socket.h include from test_etcp_two_instances.c (Linux-only) - Fix test_mkdtemp buffer overflow - use memcpy instead of strncpy - Fix test_mkdtemp return value check (replace == NULL with != 0) - Add Windows socket libraries (-lws2_32 -liphlpapi) to test builds - All tests build successfully on Linux --- tests/Makefile.am | 9 ++++++++- tests/test_etcp_two_instances.c | 3 +-- tests/test_utils.h | 6 +++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 2941b3443..59e5504bb 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -76,7 +76,14 @@ ETCP_FULL_OBJS = \ $(ETCP_CORE_OBJS) # Common libraries (libuasync.a from lib directory) -COMMON_LIBS = $(top_builddir)/lib/libuasync.a -lpthread +COMMON_LIBS = $(top_builddir)/lib/libuasync.a -lpthread $(WIN_LIBS) + +# Windows-specific libraries +if OS_WINDOWS +WIN_LIBS = -lws2_32 -liphlpapi +else +WIN_LIBS = +endif # Crypto libraries (conditional) if USE_OPENSSL diff --git a/tests/test_etcp_two_instances.c b/tests/test_etcp_two_instances.c index 8a4225cc9..4f742ca0f 100644 --- a/tests/test_etcp_two_instances.c +++ b/tests/test_etcp_two_instances.c @@ -11,7 +11,6 @@ #endif #include #include -#include #include "../src/etcp.h" #include "../src/etcp_connections.h" @@ -71,7 +70,7 @@ static const char* client_config_content = // Create temp config files static int create_temp_configs(void) { - if (test_mkdtemp(temp_dir) == NULL) { + if (test_mkdtemp(temp_dir) != 0) { fprintf(stderr, "Failed to create temp directory\n"); return -1; } diff --git a/tests/test_utils.h b/tests/test_utils.h index df50010ec..1d45c3571 100644 --- a/tests/test_utils.h +++ b/tests/test_utils.h @@ -20,7 +20,6 @@ static char test_temp_dir[MAX_PATH]; // Cross-platform mkdtemp for Windows static inline int test_mkdtemp(char *template_str) { - (void)template_str; // Not used on Windows, we generate our own path char tmp_path[MAX_PATH]; GetTempPathA(MAX_PATH, tmp_path); @@ -31,9 +30,10 @@ static inline int test_mkdtemp(char *template_str) { snprintf(test_temp_dir, sizeof(test_temp_dir), "%s\\utun_test_%08x", tmp_path, (unsigned int)rand()); if (_mkdir(test_temp_dir) == 0) { - // Copy path back to caller's buffer + // Copy path back to caller's buffer if provided if (template_str) { - strncpy(template_str, test_temp_dir, MAX_PATH); + size_t len = strlen(test_temp_dir); + memcpy(template_str, test_temp_dir, len + 1); // Include null terminator } return 0; // Success }