From 248b92939aa6efeff5d58e973b63b50f36337913 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 27 Mar 2026 09:09:27 +0100 Subject: [PATCH] cf-socket: avoid low risk integer overflow on ancient Solaris Spotted by Codex Security Closes #21111 --- lib/cf-socket.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/cf-socket.c b/lib/cf-socket.c index 091591e5db..f78f3dfdba 100644 --- a/lib/cf-socket.c +++ b/lib/cf-socket.c @@ -236,8 +236,15 @@ static void tcpkeepalive(struct Curl_cfilter *cf, * Note that the consequent probes will not be sent * at equal intervals on Solaris, but will be sent * using the exponential backoff algorithm. */ - optval = curlx_sltosi(data->set.tcp_keepcnt) * - curlx_sltosi(data->set.tcp_keepintvl); + { + int keepcnt = curlx_sltosi(data->set.tcp_keepcnt); + int keepintvl = curlx_sltosi(data->set.tcp_keepintvl); + + if(keepcnt > 0 && keepintvl > (INT_MAX / keepcnt)) + optval = INT_MAX; + else + optval = keepcnt * keepintvl; + } KEEPALIVE_FACTOR(optval); if(setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPALIVE_ABORT_THRESHOLD, (void *)&optval, sizeof(optval)) < 0) {