Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sX1jX-0013IH-4I for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jul 2024 16:54:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sX1jV-00H1WZ-L4 for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jul 2024 16:54:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sWyad-00FAs0-Fi for pgsql-hackers@lists.postgresql.org; Thu, 25 Jul 2024 13:33:03 +0000 Received: from air.basealt.ru ([194.107.17.39]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sWyab-001OzN-C9 for pgsql-hackers@lists.postgresql.org; Thu, 25 Jul 2024 13:33:02 +0000 Received: by air.basealt.ru (Postfix, from userid 490) id 38B292F2025D; Thu, 25 Jul 2024 13:33:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on air.basealt.ru X-Spam-Level: X-Spam-Status: No, score=-1.0 required=7.0 tests=ALL_TRUSTED autolearn=unavailable autolearn_force=no version=3.4.4 Received: from [10.4.160.127] (unknown [193.43.10.250]) by air.basealt.ru (Postfix) with ESMTPSA id 03E672F20257; Thu, 25 Jul 2024 13:33:00 +0000 (UTC) Content-Type: multipart/mixed; boundary="------------Deo04BfgJ24KqhDolKbluc1z" Message-ID: <6d0323c3-3f5d-4137-af73-98a5ab90e77c@altlinux.org> Date: Thu, 25 Jul 2024 16:32:59 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: pgsql-hackers@lists.postgresql.org Cc: nickel@altlinux.org, egori@altlinux.org Reply-To: kuznetsovam@altlinux.org From: Alexander Kuznetsov Subject: Possible null pointer dereference in afterTriggerAddEvent() List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------Deo04BfgJ24KqhDolKbluc1z Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 --------------Deo04BfgJ24KqhDolKbluc1z Content-Type: text/x-patch; charset=UTF-8; name="0001-Add-assertion-of-an-empty-list-in-afterTriggerAddEve.patch" Content-Disposition: attachment; filename*0="0001-Add-assertion-of-an-empty-list-in-afterTriggerAddEve.pa"; filename*1="tch" Content-Transfer-Encoding: base64 RnJvbSBhY2FiZTM0YjcxNGE5YzMxMWJmYjg1ZTViZTk0ZTZmZTkwNmZhOWYxIE1vbiBTZXAg MTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBBbGV4YW5kZXIgS3V6bmV0c292IDxrdXpuZXRzb3Zh bUBhbHRsaW51eC5vcmc+CkRhdGU6IFRodSwgMjUgSnVsIDIwMjQgMTY6MjQ6MTggKzAzMDAK U3ViamVjdDogW1BBVENIXSBBZGQgYXNzZXJ0aW9uIG9mIGFuIGVtcHR5IGxpc3QgaW4gYWZ0 ZXJUcmlnZ2VyQWRkRXZlbnQoKQoKSXQgaXMgcG9zc2libGUgZm9yIGV2ZW50cy0+dGFpbCB0 byBzdGlsbCBiZSBOVUxMIGF0IHRoaXMgcG9pbnQsCnNvI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