os: xtrans: fix calloc overflow warning

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 <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2025-06-30 13:20:36 +02:00
parent cc39bf7745
commit 9ddc54918a
3 changed files with 6 additions and 4 deletions

View File

@ -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 };

View File

@ -50,6 +50,8 @@ from The Open Group.
#ifndef _XTRANS_H_
#define _XTRANS_H_
#include <stdint.h>
#include <X11/Xfuncproto.h>
#include <X11/Xos.h>
#include <X11/Xmd.h>
@ -289,7 +291,7 @@ int _XSERVTransGetConnectionNumber (
int _XSERVTransMakeAllCOTSServerListeners (
const char *, /* port */
int *, /* partial */
int *, /* count_ret */
uint32_t *, /* count_ret */
XtransConnInfo ** /* ciptrs_ret */
);

View File

@ -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 */ );