From 30c4d08128faf671d252cb333fe5511a1083ac67 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Fri, 17 Jul 2026 17:43:13 -0700 Subject: [PATCH 1/2] wolfSSH_get_fd: return socket sentinel on NULL - Return -1 on both (Windows build and not), the sentinel wolfSSH_new() uses for rfd/wfd. --- src/ssh.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ssh.c b/src/ssh.c index 57089ec95..81627fe8b 100644 --- a/src/ssh.c +++ b/src/ssh.c @@ -258,10 +258,13 @@ WS_SOCKET_T wolfSSH_get_fd(const WOLFSSH* ssh) if (ssh) return ssh->rfd; + /* Return the same invalid-socket sentinel wolfSSH_new() initializes + * rfd/wfd to, rather than an error enum, so callers get a value of the + * socket type they can compare against. */ #ifdef USE_WINDOWS_API return INVALID_SOCKET; #else - return WS_BAD_ARGUMENT; + return -1; #endif } From bee9b339c56e3c1b571682f1bf40cccceebaccbd Mon Sep 17 00:00:00 2001 From: John Safranek Date: Thu, 10 Sep 2026 17:29:00 -0700 Subject: [PATCH 2/2] tests: pin the get_fd invalid-socket sentinel test_wolfSSH_set_fd() compares the NULL return of wolfSSH_get_fd() against the platform invalid-socket sentinel, the value wolfSSH_new() initializes rfd/wfd to. The old check only asserted the result was not WS_SUCCESS, which the previous WS_BAD_ARGUMENT return also satisfied. --- tests/api.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/api.c b/tests/api.c index 55009434c..5635e2a5a 100644 --- a/tests/api.c +++ b/tests/api.c @@ -238,7 +238,11 @@ static void test_wolfSSH_set_fd(void) AssertIntNE(WS_SUCCESS, wolfSSH_set_fd(NULL, fd)); check = wolfSSH_get_fd(NULL); - AssertFalse(WS_SUCCESS == check); +#ifdef USE_WINDOWS_API + AssertTrue(INVALID_SOCKET == check); +#else + AssertTrue(-1 == check); +#endif AssertIntEQ(WS_SUCCESS, wolfSSH_set_fd(ssh, fd)); check = wolfSSH_get_fd(ssh);