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 1syYXU-000lL8-HO for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Oct 2024 15:23:49 +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 1syYXT-002YFy-MK for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Oct 2024 15:23:48 +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 1syYXT-002YFo-CP for pgsql-hackers@lists.postgresql.org; Wed, 09 Oct 2024 15:23:47 +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 1syYXQ-0003SH-Lt for pgsql-hackers@lists.postgresql.org; Wed, 09 Oct 2024 15:23:46 +0000 Received: by air.basealt.ru (Postfix, from userid 490) id 45FF72F2023B; Wed, 9 Oct 2024 15:23:41 +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=-2.9 required=7.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 Received: from [10.4.129.65] (unknown [193.43.10.250]) by air.basealt.ru (Postfix) with ESMTPSA id A112C2F2022C; Wed, 9 Oct 2024 15:23:40 +0000 (UTC) Message-ID: Date: Wed, 9 Oct 2024 18:23:40 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Reply-To: kuznetsovam@altlinux.org Subject: Re: [PATCH] Check for TupleTableSlot nullness before dereferencing To: Daniel Gustafsson Cc: PostgreSQL Developers , egori@altlinux.org, nickel@altlinux.org References: <98e18ffc-c402-4710-ae28-6d6dbcf08e44@altlinux.org> Content-Language: en-US From: Alexander Kuznetsov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 03.10.2024 12:48, Daniel Gustafsson wrote: > From a quick reading we can only reach there after evaluating an expression, so > can it really be null though? This code hasn't changed all that much since > 2009, if there was a reachable segfault on a null pointer deref I have a > feeling we'd heard about it by now so some extra care seems warranted to ensure > it's not a static analyzer false positive. Thanks for your response! It seems to me that dereferencing is possible under the following scenario: 1. slot2 is NULL at line 968, 2. The while loop at line 971 executes once, filling slot1 (slot2 still remains NULL), 3. No changes occur to slot2 thereafter, up to line 1003, 4. At line 1003, slot2 is swapped with slot1 (assuming numDistinctCols > 0), 5. At line 1016, slot1 is dereferenced with conent of slot2 (NULL). This entire reasoning is based on the assumption that slot2 can theoretically be NULL, as there is such a check at line 968. Is it possible that no errors have occurred because this condition has always been satisfied and is, perhaps, redundant, or maybe I'm misunderstanding something? -- Best regards, Alexander Kuznetsov