From: Alexander Kuznetsov <kuznetsovam@altlinux.org>
To: pgsql-hackers@lists.postgresql.org
Cc: nickel@altlinux.org
Cc: egori@altlinux.org
Subject: Possible null pointer dereference in afterTriggerAddEvent()
Date: Thu, 25 Jul 2024 16:32:59 +0300
Message-ID: <6d0323c3-3f5d-4137-af73-98a5ab90e77c@altlinux.org> (raw)
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
Attachments:0001-Add-assertion-of-an-empty-list-in-afterTriggerAddEve.patch (text/x-patch, 982B) download
From acabe34b714a9c311bfb85e5be94e6fe906fa9f1 Mon Sep 17 00:00:00 2001
From: Alexander Kuznetsov <kuznetsovam@altlinux.org>
Date: Thu, 25 Jul 2024 16:24:18 +0300
Subject: [PATCH] Add assertion of an empty list in afterTriggerAddEvent()
It is possible for events->tail to still be NULL at this point,
so assert it's not NULL before dereferencing.
This was found by ALT Linux Team with Svace.
---
src/backend/commands/trigger.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.cindex 170360edda..a0946025a5 100644--- a/src/backend/commands/trigger.c+++ b/src/backend/commands/trigger.c@@ -4099,7 +4099,10 @@ afterTriggerAddEvent(AfterTriggerEventList *events,
if (events->head == NULL)
events->head = chunk;
else
+ {+ Assert(events->tail != NULL);
events->tail->next = chunk;
+ }
events->tail = chunk;
/* events->tailfree is now out of sync, but we'll fix it below */
}
--
2.42.2
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: kuznetsovam@altlinux.org, nickel@altlinux.org, egori@altlinux.org
Subject: Re: Possible null pointer dereference in afterTriggerAddEvent()
In-Reply-To: <6d0323c3-3f5d-4137-af73-98a5ab90e77c@altlinux.org>
References: <6d0323c3-3f5d-4137-af73-98a5ab90e77c@altlinux.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox