From 74f1547a7056a3cb51e030d5033cc29d89b9632f Mon Sep 17 00:00:00 2001 From: Dennis Park Date: Mon, 3 Aug 2026 12:23:04 +0900 Subject: [PATCH 1/2] fix: clear the compiler warnings on Linux and Windows gcc had two, MSVC fourteen, and none of them were noise: - The HTTP connection pool keys itself on "host:port" in a buffer as wide as the host field alone, so gcc warned that the port could be truncated away. Two hosts differing only past that point would then share one pool. The host width and the key width are now named and the key is the wider of the two. - CMUTIL_SocketConnectIPCInternal passed a struct sockaddr_in* where a CMUTIL_SocketAddr* was expected. Same address either way, so the code worked, but the declared types disagreed - it now passes the storage it meant to. - select() takes an int nfds, and a SOCKET is a 64 bit handle on Windows where that argument is ignored outright; connect() and bind() take a socklen_t, not a size_t; Socket::Write and ByteBuffer::AddBytes take a uint32_t, not a size_t. All now say so. - crypto_test declared an EVP_CIPHER it never used. Co-Authored-By: Claude Opus 5 (1M context) --- src/http.c | 18 ++++++++++++------ src/network.c | 16 +++++++++------- test/crypto_test.c | 2 -- test/dgram_test.c | 6 +++--- test/network_test.c | 6 +++--- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/http.c b/src/http.c index 3f2744e..1f87209 100644 --- a/src/http.c +++ b/src/http.c @@ -39,6 +39,12 @@ CMUTIL_LogDefine("cmutils.http") // absurd or hostile length headers. #define CMUTIL_HTTP_MAX_BODY (1024L*1024L*1024L) +// How wide a host name this client stores, and how wide the "host:port" +// key derived from it can get - a truncated key would let two different +// hosts share one connection pool. +#define CMUTIL_HTTP_HOST_MAX 256 +#define CMUTIL_HTTP_POOLKEY_MAX (CMUTIL_HTTP_HOST_MAX + 16) + struct CMUTIL_HttpContext { CMUTIL_Map *socket_pools; CMUTIL_Mutex *socket_pools_mutex; @@ -48,7 +54,7 @@ struct CMUTIL_HttpContext { typedef struct CMUTIL_SocketPoolElem { time_t last_used; CMUTIL_Mem *memst; - char host[256]; + char host[CMUTIL_HTTP_HOST_MAX]; int port; CMUTIL_Socket *sock; } CMUTIL_SocketPoolElem; @@ -120,7 +126,7 @@ CMUTIL_STATIC CMUTIL_Socket *CMUTIL_HttpContextGetSocket( { CMUTIL_Pool *pool = NULL; CMUTIL_SocketPoolElem *elem = NULL; - char buf[256]; + char buf[CMUTIL_HTTP_POOLKEY_MAX]; snprintf(buf, sizeof(buf), "%s:%d", host, port); CMCall(g_httpctx.socket_pools_mutex, Lock); pool = CMCall(g_httpctx.socket_pools, Get, buf); @@ -164,7 +170,7 @@ CMUTIL_STATIC CMBool CMUTIL_HttpContextPutSocket( const char *host, int port, CMUTIL_Socket *sock) { CMUTIL_Pool *pool = NULL; - char buf[256]; + char buf[CMUTIL_HTTP_POOLKEY_MAX]; CMBool res = CMFalse; snprintf(buf, sizeof(buf), "%s:%d", host, port); CMCall(g_httpctx.socket_pools_mutex, Lock); @@ -192,7 +198,7 @@ CMUTIL_STATIC CMBool CMUTIL_HttpContextPutSocket( typedef struct CMUTIL_HttpClient_Internal { CMUTIL_HttpClient base; CMUTIL_Mem *memst; - char host[256]; + char host[CMUTIL_HTTP_HOST_MAX]; int port; CMBool ishttps; CMBool verifypeer; @@ -329,7 +335,7 @@ CMUTIL_STATIC CMSocketResult CMUTIL_HttpClientWriteLine( { CMSocketResult sr = CMSocketOk; if (line && *line) - sr = CMCall(sock, Write, line, strlen(line), timeout); + sr = CMCall(sock, Write, line, (uint32_t)strlen(line), timeout); if (sr == CMSocketOk) sr = CMCall(sock, Write, "\r\n", 2, timeout); CMLogTrace("Write -> %s", line); @@ -438,7 +444,7 @@ CMUTIL_STATIC CMUTIL_ByteBuffer *CMUTIL_HttpClientRequest( // Content-Length already delimits the body. A CRLF after it is // extra bytes the peer reads as the start of the next request, // which desynchronizes a kept-alive connection. - sr = CMCall(sock, Write, data, size, timeout); + sr = CMCall(sock, Write, data, (uint32_t)size, timeout); if (sr != CMSocketOk) { CMLogError("failed to write request body"); goto FAILED; diff --git a/src/network.c b/src/network.c index ced2a6b..4ab9979 100644 --- a/src/network.c +++ b/src/network.c @@ -406,10 +406,12 @@ CMSocketResult CMUTIL_SocketCheckBase( tv.tv_sec = timeout / 1000; tv.tv_usec = (int)((timeout % 1000) * 1000); + // nfds is an int; a SOCKET is a 64 bit handle on Windows, where the + // argument is ignored outright. if (isread) { - rc = select(sock+1, &fdset, NULL, NULL, &tv); + rc = select((int)(sock+1), &fdset, NULL, NULL, &tv); } else { - rc = select(sock+1, NULL, &fdset, NULL, &tv); + rc = select((int)(sock+1), NULL, &fdset, NULL, &tv); } if (rc < 0) { if (!silent) @@ -837,7 +839,7 @@ CMUTIL_STATIC CMBool CMUTIL_SocketConnectByIP( return CMFalse; } - rc = connect(s, (struct sockaddr*)addr, addrlen); + rc = connect(s, (struct sockaddr*)addr, (socklen_t)addrlen); is->sock = s; if (rc < 0) { @@ -1128,9 +1130,9 @@ CMUTIL_STATIC CMBool CMUTIL_SocketConnectIPCInternal( { struct sockaddr_storage ss; #if defined(MSWIN) - struct sockaddr_in *sin = (struct sockaddr_in*)&ss; - long port = strtol(ipc_path, NULL, 10); - CMUTIL_SocketAddrSet(sin, "127.0.0.1", port); + // IPC is a loopback connection here, with the path naming the port. + const long port = strtol(ipc_path, NULL, 10); + CMUTIL_SocketAddrSet(&ss, "127.0.0.1", (int)port); #else struct sockaddr_un *sun = (struct sockaddr_un*)&ss; if (strlen(ipc_path) >= sizeof(sun->sun_path) - 1) { @@ -1394,7 +1396,7 @@ CMUTIL_STATIC CMBool CMUTIL_ServerSocketCreateBase( goto FAILED; } - rc = bind(sock, (struct sockaddr *) &addr, addrlen); + rc = bind(sock, (struct sockaddr *) &addr, (socklen_t)addrlen); if (rc == SOCKET_ERROR) { if (res->silent) CMLogTrace("bind failed.(%d:%s)", errno, strerror(errno)); diff --git a/test/crypto_test.c b/test/crypto_test.c index 4de3677..ef12497 100644 --- a/test/crypto_test.c +++ b/test/crypto_test.c @@ -81,8 +81,6 @@ int main() { OpenSSL_add_all_algorithms(); CMUTIL_Init(CMUTIL_MEM_TYPE); - EVP_CIPHER *cipher; - CMUTIL_BlockCrypto *block = NULL; CMUTIL_Map *env = NULL; CMUTIL_String *pathstr = NULL; diff --git a/test/dgram_test.c b/test/dgram_test.c index 61a918a..af28b0a 100644 --- a/test/dgram_test.c +++ b/test/dgram_test.c @@ -92,7 +92,7 @@ int main() { CMLogInfo("datagram socket connected to %s:%d", rhost, rport); const char *send_data = "this is sample message"; - CMCall(buffer, AddBytes, (const uint8_t*)send_data, strlen(send_data)); + CMCall(buffer, AddBytes, (const uint8_t*)send_data, (uint32_t)strlen(send_data)); sr = CMCall(client, Send, buffer, 1000); ASSERT(sr == CMSocketOk, "Send"); @@ -108,7 +108,7 @@ int main() { client = CMUTIL_DGramSocketCreateBind(NULL); send_data = "second data"; - CMCall(buffer, AddBytes, (const uint8_t*)send_data, strlen(send_data)); + CMCall(buffer, AddBytes, (const uint8_t*)send_data, (uint32_t)strlen(send_data)); sr = CMCall(client, SendTo, buffer, &localaddr, 1000); ASSERT(sr == CMSocketOk, "SendTo"); @@ -127,7 +127,7 @@ int main() { CMCall(buffer, Clear); send_data = "!@#$$#@!"; - CMCall(buffer, AddBytes, (const uint8_t*)send_data, strlen(send_data)); + CMCall(buffer, AddBytes, (const uint8_t*)send_data, (uint32_t)strlen(send_data)); sr = CMCall(client, SendTo, buffer, &localaddr, 1000); if (sr != CMSocketOk) { CMLogError("datagram socket send failed - failed"); diff --git a/test/network_test.c b/test/network_test.c index c721b53..75fc5ef 100644 --- a/test/network_test.c +++ b/test/network_test.c @@ -38,7 +38,7 @@ void client_handler(void* udata) { CMCall(str, InsertPrint, 0, "%04d", len); p = (uint8_t*)CMCall(str, GetCString); blen = CMCall(str, GetSize); - sr = CMCall(csock, Write, p, blen, 1000); + sr = CMCall(csock, Write, p, (uint32_t)blen, 1000); if (sr != CMSocketOk) break; CMLogInfo("sent to client: %s", CMCall(str, GetCString)); CMCall(buf, Clear); @@ -93,11 +93,11 @@ void client_proc(void* udata) { CMLogInfo("connected to server: %s:%d", host, port); for (int i=0; i<10; i++) { CMCall(sbuf, AddPrint, "%s: %d", tname, i); - int len = CMCall(sbuf, GetSize); + int len = (int)CMCall(sbuf, GetSize); CMCall(sbuf, InsertPrint, 0, "%04d", len); uint8_t *p = (uint8_t*)CMCall(sbuf, GetCString); size_t blen = CMCall(sbuf, GetSize); - sr = CMCall(csock, Write, p, blen, 1000); + sr = CMCall(csock, Write, p, (uint32_t)blen, 1000); if (sr != CMSocketOk) break; CMLogInfo("sent to server: %s", CMCall(sbuf, GetCString)); CMCall(sbuf, Clear); From 644afdb3ae93c7cd302c65e489cdc14dd98167c6 Mon Sep 17 00:00:00 2001 From: Dennis Park Date: Mon, 3 Aug 2026 12:27:27 +0900 Subject: [PATCH 2/2] fix: pass the PEM passphrase as bytes in crypto_test CMUTIL_PrivateKeyCreateFromPEM takes a const uint8_t*, which clang on macOS flagged for the empty string literal handed to it. Co-Authored-By: Claude Opus 5 (1M context) --- test/crypto_test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/crypto_test.c b/test/crypto_test.c index ef12497..b90532b 100644 --- a/test/crypto_test.c +++ b/test/crypto_test.c @@ -196,7 +196,8 @@ int main() { "6wIDAQAB\n" "-----END PUBLIC KEY-----"; - priv = CMUTIL_PrivateKeyCreateFromPEM(priv_pem, ""); + /* the passphrase is bytes, not text */ + priv = CMUTIL_PrivateKeyCreateFromPEM(priv_pem, (const uint8_t*)""); ASSERT(priv != NULL, "CMUTIL_PrivateKeyCreateFromPEM"); pub = CMUTIL_PublicKeyCreateFromPEM(pub_pem);