From 9ddc54918a247c8ce5b265a4b3ff53d0d350b2c8 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Mon, 30 Jun 2025 13:20:36 +0200 Subject: [PATCH] os: xtrans: fix calloc overflow warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The size of `int` is machine specific and may be 64 bits wide, which could overflow the calloc'able size. Practically cannot happen here, since the ListenTransCount can't go above MAX_CONNECTIONS, but compiler can't know that and so spitting out a warning. Using uint32_t really is sufficient here. > ../os/connection.c: In function ‘CreateWellKnownSockets’: > ../os/connection.c:274:22: warning: argument 1 range [18446744071562067968, 18446744073709551615] exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=] > 274 | ListenTransFds = calloc(ListenTransCount, sizeof(int)); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Enrico Weigelt, metux IT consult --- os/Xtrans.c | 4 ++-- os/Xtrans.h | 4 +++- os/connection.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/os/Xtrans.c b/os/Xtrans.c index 2063793df..0433d08a4 100644 --- a/os/Xtrans.c +++ b/os/Xtrans.c @@ -881,7 +881,7 @@ complete_network_count (void) static int receive_listening_fds(const char* port, XtransConnInfo* temp_ciptrs, - int* count_ret) + uint32_t* count_ret) { #ifdef HAVE_SYSTEMD_DAEMON @@ -958,7 +958,7 @@ extern int xquartz_launchd_fd; #endif int _XSERVTransMakeAllCOTSServerListeners (const char *port, int *partial, - int *count_ret, XtransConnInfo **ciptrs_ret) + uint32_t *count_ret, XtransConnInfo **ciptrs_ret) { char buffer[256]; /* ??? What size ?? */ XtransConnInfo ciptr, temp_ciptrs[NUMTRANS] = { NULL }; diff --git a/os/Xtrans.h b/os/Xtrans.h index fa40550e4..fb7ceaadd 100644 --- a/os/Xtrans.h +++ b/os/Xtrans.h @@ -50,6 +50,8 @@ from The Open Group. #ifndef _XTRANS_H_ #define _XTRANS_H_ +#include + #include #include #include @@ -289,7 +291,7 @@ int _XSERVTransGetConnectionNumber ( int _XSERVTransMakeAllCOTSServerListeners ( const char *, /* port */ int *, /* partial */ - int *, /* count_ret */ + uint32_t *, /* count_ret */ XtransConnInfo ** /* ciptrs_ret */ ); diff --git a/os/connection.c b/os/connection.c index 20e37fa14..dec7a340b 100644 --- a/os/connection.c +++ b/os/connection.c @@ -144,7 +144,7 @@ set_poll_clients(void); static XtransConnInfo *ListenTransConns = NULL; static int *ListenTransFds = NULL; -static int ListenTransCount; +static uint32_t ListenTransCount = 0; static void ErrorConnMax(XtransConnInfo /* trans_conn */ );