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 1sXHKt-002wVy-MS for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Jul 2024 09:34:03 +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 1sXHKs-008zjT-8y for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Jul 2024 09:34:02 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sXH3X-008l21-53 for pgsql-hackers@lists.postgresql.org; Fri, 26 Jul 2024 09:16:07 +0000 Received: from air.basealt.ru ([194.107.17.39]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sXH3T-001WdO-Dm for pgsql-hackers@lists.postgresql.org; Fri, 26 Jul 2024 09:16:05 +0000 Received: by air.basealt.ru (Postfix, from userid 490) id B7FF62F20246; Fri, 26 Jul 2024 09:16: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 801A42F20226; Fri, 26 Jul 2024 09:16:00 +0000 (UTC) Content-Type: multipart/mixed; boundary="------------FXCiXxVtD21OO4W1yy0OnawH" Message-ID: <8ddb8e6a-e899-4218-870f-8b25da3a9f3f@altlinux.org> Date: Fri, 26 Jul 2024 12:16:00 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Reply-To: kuznetsovam@altlinux.org Subject: Re: Possible null pointer dereference in afterTriggerAddEvent() To: Alvaro Herrera Cc: pgsql-hackers@lists.postgresql.org, nickel@altlinux.org, egori@altlinux.org References: <202407251707.tkkrcs7c4eso@alvherre.pgsql> Content-Language: en-US From: Alexander Kuznetsov In-Reply-To: <202407251707.tkkrcs7c4eso@alvherre.pgsql> 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. --------------FXCiXxVtD21OO4W1yy0OnawH Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 25.07.2024 20:07, Alvaro Herrera wrote: > Maybe for sanity (and perhaps for Svace compliance) we could do it the > other way around, i.e. by testing events->tail for nullness instead of > events->head, then add the assertion: > > if (events->tail == NULL) > { > Assert(events->head == NULL); > events->head = chunk; > } > else > events->tail->next = chunk; > > This way, it's not wholly redundant. Thanks for your response! I agree with the proposed changes and have updated the patch accordingly. Version 2 is attached. > That said, I'm not sure we actually *need* to change this. I understand and partly agree. But it appears that with these changes, the dereference of a null pointer is impossible even in builds where assertions are disabled. Previously, this issue could theoretically occur. Consequently, these changes slightly enhance overall security. -- Best regards, Alexander Kuznetsov --------------FXCiXxVtD21OO4W1yy0OnawH Content-Type: text/x-patch; charset=UTF-8; name="v2-0001-Add-assertion-of-an-empty-list-in-afterTriggerAdd.patch" Content-Disposition: attachment; filename*0="v2-0001-Add-assertion-of-an-empty-list-in-afterTriggerAdd.pa"; filename*1="tch" Content-Transfer-Encoding: base64 RnJvbSA2M2EzYTE5ZmU2N2JmZDFmNDI3YjIxZDUzZmYwZWY2NDJhZWQ4OWM0IE1vbiBTZXAg MTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBBbGV4YW5kZXIgS3V6bmV0c292IDxrdXpuZXRzb3Zh bUBhbHRsaW51eC5vcmc+CkRhdGU6IEZyaSwgMjYgSnVsIDIwMjQgMTE6NTU6NTMgKzAzMDAK U3ViamVjdDog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