Xext: sync: protect from NULL pointer dereference

> ../Xext/sync.c: In function ‘IdleTimeQueryValue’:
> ../Xext/sync.c:2654:18: warning: dereference of NULL ‘priv’ [CWE-476] [-Wanalyzer-null-dereference]
>  2654 |         deviceid = priv->deviceid;
>       |         ~~~~~~~~~^~~~~~~~~~~~~~~~

> ../Xext/sync.c: In function ‘IdleTimeBlockHandler’:
> ../Xext/sync.c:2666:14: warning: dereference of NULL ‘priv’ [CWE-476] [-Wanalyzer-null-dereference]
>  2666 |     int64_t *less = priv->value_less;
>       |              ^~~~

> ../Xext/sync.c:2773:9: warning: dereference of NULL ‘priv’ [CWE-476] [-Wanalyzer-null-dereference]
>  2773 |     if (LastEventTimeWasReset(priv->deviceid)) {
>       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

> ../Xext/sync.c: In function ‘IdleTimeBracketValues’:
> ../Xext/sync.c:2791:14: warning: dereference of NULL ‘priv’ [CWE-476] [-Wanalyzer-null-dereference]
>  2791 |     int64_t *less = priv->value_less;
>       |              ^~~~

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2025-05-06 17:07:05 +02:00
parent 746648be85
commit 0e8ff0bf57

View File

@ -2647,16 +2647,15 @@ typedef struct {
static void
IdleTimeQueryValue(void *pCounter, int64_t *pValue_return)
{
int deviceid;
int deviceid = XIAllDevices;
CARD32 idle;
if (pCounter) {
SyncCounter *counter = pCounter;
IdleCounterPriv *priv = SysCounterGetPrivate(counter);
deviceid = priv->deviceid;
if (priv)
deviceid = priv->deviceid;
}
else
deviceid = XIAllDevices;
idle = GetTimeInMillis() - LastEventTime(deviceid).milliseconds;
*pValue_return = idle;
}
@ -2666,6 +2665,8 @@ IdleTimeBlockHandler(void *pCounter, void *wt)
{
SyncCounter *counter = pCounter;
IdleCounterPriv *priv = SysCounterGetPrivate(counter);
if (!priv)
return;
int64_t *less = priv->value_less;
int64_t *greater = priv->value_greater;
int64_t idle, old_idle;
@ -2756,6 +2757,8 @@ IdleTimeWakeupHandler(void *pCounter, int rc)
{
SyncCounter *counter = pCounter;
IdleCounterPriv *priv = SysCounterGetPrivate(counter);
if (!priv)
return;
int64_t *less = priv->value_less;
int64_t *greater = priv->value_greater;
int64_t idle;
@ -2789,6 +2792,8 @@ IdleTimeBracketValues(void *pCounter, int64_t *pbracket_less,
{
SyncCounter *counter = pCounter;
IdleCounterPriv *priv = SysCounterGetPrivate(counter);
if (!priv)
return;
int64_t *less = priv->value_less;
int64_t *greater = priv->value_greater;
Bool registered = (less || greater);