Possible null pointer dereference in afterTriggerAddEvent()

Alexander Kuznetsov <kuznetsovam@altlinux.org>

From: Alexander Kuznetsov <kuznetsovam@altlinux.org>
To: pgsql-hackers@lists.postgresql.org
Cc: nickel@altlinux.org, egori@altlinux.org
Date: 2024-07-25T13:32:59Z
Lists: pgsql-hackers

Attachments

Hello everyone,

In src/backend/commands/trigger.c:4031, there is an afterTriggerAddEvent() function. The variable chunk is assigned the value of events->tail at line 4050. Subsequently, chunk is compared to NULL at lines 4051 and 4079, indicating that events->tail could potentially be NULL.

However, at line 4102, we dereference events->tail by accessing events->tail->next without first checking if it is NULL.

To address this issue, I propose at least adding an assertion to ensure that events->tail != NULL before the dereference. The suggested patch is included in the attachment.

-- 
Best regards,
Alexander Kuznetsov

Commits

  1. Turn 'if' condition around to avoid Svace complaint