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 1ttVH5-00DFuZ-0H for pgsql-bugs@arkaria.postgresql.org; Sat, 15 Mar 2025 17:26:15 +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 1ttVH3-00HXQN-OI for pgsql-bugs@arkaria.postgresql.org; Sat, 15 Mar 2025 17:26:13 +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 1ttVDy-00HSbC-62 for pgsql-bugs@lists.postgresql.org; Sat, 15 Mar 2025 17:23:02 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1ttVDv-0030Qn-1c for pgsql-bugs@lists.postgresql.org; Sat, 15 Mar 2025 17:23:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 52FHMvih3487877; Sat, 15 Mar 2025 13:22:58 -0400 From: Tom Lane To: Daniel Gustafsson cc: pm91.arapov@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18845: DEREF_OF_NULL.RET guc_malloc possibly returns NULL In-reply-to: References: <18845-582c6e10247377ec@postgresql.org> <3051193.1741961099@sss.pgh.pa.us> Comments: In-reply-to Daniel Gustafsson message dated "Fri, 14 Mar 2025 23:10:27 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3487875.1742059377.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 15 Mar 2025 13:22:57 -0400 Message-ID: <3487876.1742059377@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Daniel Gustafsson writes: > On 14 Mar 2025, at 15:04, Tom Lane wrote: >> Indeed. Also, a quick survey shows a lot of inconsistency in >> guc_malloc callers --- some are lazy and just use ERROR rather >> than LOG-and-return. That's probably all right for PGC_POSTMASTER >> variables (since there's no chance of continuing anyway) but >> perhaps it's worth improving elsewhere. > Turns out there was one more guc_malloc(LOG.. which didn't inspect the > returned allocation in check_synchronized_standby_slots. On top of that= there > were a few non PGC_POSTMASTER check functions that could return false an= d let > the GUC machinery handle it if we want to be consistent. Patch looks good as far as it goes, but I nosed around and found a few other things: * After sleeping on it, I think we ought to change the guc_malloc(ERROR,...) calls in the PGC_POSTMASTER cases too. While this won't have any functional effect, what it does do is remove examples of bad practice that are likely to get copied-and-pasted to somewhere where it matters. The affected functions seem to be check_recovery_target_lsn check_recovery_target_timeline check_recovery_target_xid check_debug_io_direct * check_application_name and check_cluster_name are using WARNING not LOG in their guc_strdup calls. That seems to have been decided by flipping a coin; let's sync them with everyplace else. * init_custom_variable uses ERROR in a guc_malloc and a guc_strdup call. These should probably be changed to FATAL, on the same grounds that the error levels earlier in that function are FATAL: we are partway through initializing a newly-loaded extension, so it's unlikely that trying to continue the session is going to end well. I agree that in the back branches it's sufficient to fix check_createrole_self_grant and check_synchronized_standby_slots. The rest of this is mostly about setting good examples. regards, tom lane