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.96) (envelope-from ) id 1w4rb0-002dG4-2F for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Mar 2026 02:34:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w4ray-003f09-37 for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Mar 2026 02:34:17 +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.96) (envelope-from ) id 1w4ray-003f00-2C for pgsql-hackers@lists.postgresql.org; Tue, 24 Mar 2026 02:34:17 +0000 Received: from mail-qt1-x832.google.com ([2607:f8b0:4864:20::832]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w4rax-00000000ihj-1FdN for pgsql-hackers@postgresql.org; Tue, 24 Mar 2026 02:34:16 +0000 Received: by mail-qt1-x832.google.com with SMTP id d75a77b69052e-5091d71aa11so58733391cf.1 for ; Mon, 23 Mar 2026 19:34:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774319654; cv=none; d=google.com; s=arc-20240605; b=B3TVEM0T8jwWR8gWGxTE7x3vtRZvQAx21yorDM/30TcDnYIvFuOWJANAdWvEcJ0Dfy mTvCdDeP20Nm98QtqCpXER5HXPcRJMOpZUSv1LbMO0WabTSNVtQjHwd/BVeds95J5+pS /qsFV0EXYduKfAdmIlA4N3mWW2U8wlhG4kMkX7Yu8c+hNWjmcdVklSYIxhk9aChdHAAf o50YBpGNUeOANJ1K2ZPh++NYcm7bI8suSUwcksdv1MDh9k+NZKBglwckPrRDCpzgbFH9 ILdI+LzFU7YJI/XH/XYALrfz9FPUSfpgKlxAFgvBficwJdhT3SsITkCVFJX5H0KsBxca qi/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=oTmaEUMtS698ifLWP3lNooSaUarBL2P87ZAmRPmuCIA=; fh=J0uDjzSKogBsD9n/jaNPZHLBaUlEVb94pwhYPUWBmj8=; b=Twhsw0C7F++SKXyRj9paCK0VEl+1o/Dk24nadrI/cXxLl5XNABoPdWMlEX9vqhYrht 0iuFKRVfw2p+ugWczhg1dPnh3GTXRfawf/UBtbImjpzoQOlX7BaUcViuDNNImi9Qnxth 8pEBF1dUZ/Old5ojoReqZv3GMRRs8DdHMrtlkTByJIwlb8mw4/kHsgx7xbbKROmZj2Vm 1ENhv5rPWoYoKsXkCzMirhsgtz+e37Rhj6hy92zcQQkcMGA/0iITDxOz0Qodj+TbOKSR Mvp9OjbhC+vVbfc37Wq+XMAHo+6rzUoaTOG3H13EkmcL69Wc8M+VbNRloSyulCZchft0 uzgg==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774319654; x=1774924454; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=oTmaEUMtS698ifLWP3lNooSaUarBL2P87ZAmRPmuCIA=; b=hTB1BV+8Wh2TUZkTC4anQoQgmPC5fP7U/NCXvb+463j5LRv05sPa7zCsEmv9vkmAuA pP5d5tALKNhb88m/SYNScK4jxgWT/gAPQ8KhOvhRryHgsOKvlrHxeOrrdisgst0sqzru rRllsTxpjQM0D4Rnf8wO4lnWQK2Br2JqzFpq6CwsI7Z3TANcbsthmOwc0vxIpgmt4i4d Nsmm86u/Bon1Q5p3BmjcCO+32Piye4oq0ufzP5e+pL6lk9t4Vk55koZvC3ChRKqU8IEs LMoi2WqpLAq7xyf/u7ofX1PxMlHcQlzrqhQDFjZw2SzWWKQKp6TwKOzQNiOvgagwiSsa buKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774319654; x=1774924454; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=oTmaEUMtS698ifLWP3lNooSaUarBL2P87ZAmRPmuCIA=; b=j901+SGFHLC1VoZFfzpvEz2j4sJwKHO+DcYXnYUw9FMpCcYKTSXYJszXfBGGbeXr7x uCzyZagnqBg+9mUKRxDrqOa1uuK/v0oGASX6amBsw6K1GWBCArcbT5PAnr7WFFqw++vp HVOCz4CsXboPFstzNFvhNDLMVx4NfnL4K/+5ld3aZ6BqQihTqDgBm3TZIjAJzdh5+ccO /tEr1UB2hQaUJ7f9Ym2kQguQj1X1X/IHR6is+LiQdYFAzrTYHYPlj6X5muy+rlO3u8z0 e+b3Sn8njvZMJYmiogD673/SUGAX93sXGln37I7EHMmgjThYjxuxG3QouA9PwT099Bzq ittA== X-Forwarded-Encrypted: i=1; AJvYcCUhNhfYweAdvRJb+wKA+Mf9mQzUlnaDvDy/KkTOYL6tY5FVetmhJ0pcEYQkBaQwcoCYevK23wmGW6uKFGJ1@postgresql.org X-Gm-Message-State: AOJu0Yzwm4O5yp1UEEiJyUThYmWLTEaRZf8ymMRosmVW7RE0BG69Ii1D uagmDHoc3Rzoi8xj3D1WNvzOxSvOVJk1CFjKuorsDkMf9OYzou8vW3XWP9vkZTT7rL44NbzmqeG iX6HDzZOXEwhH1fTXVegosvdEeKgwCU0= X-Gm-Gg: ATEYQzzc9SIDT71GJ03QPJztCPSjWScj8jzGR+66FWv5fBbhqLqJMmvOT4etEBKog2M Dz2pOXhrRjisVX6LxS+dGthTUjRYOnK1SL+eHcgK6WwA7VNb5dZj9UA7PC+wvfefJeKhktglrTl O9ZhNtRq/XlqdIdV2B0B2zsb1qaKj7R7qPKBeOusoFZYdzOEZYGHMQF2faRMU5h/VBw3cmKttVF A6nScCBbzhfEq1SG2FtM+YvSOfmG4nEGVWc7edFjfoO5UiFCiImHRsNW7jnP19CRX+uIyQf3wfZ jSXTRR6cHbaz79RPR7dv X-Received: by 2002:a05:622a:858e:b0:509:144a:43bd with SMTP id d75a77b69052e-50b6ed43393mr21400381cf.3.1774319654397; Mon, 23 Mar 2026 19:34:14 -0700 (PDT) MIME-Version: 1.0 References: <3007317.1765210195@sss.pgh.pa.us> In-Reply-To: From: Mahendra Singh Thalor Date: Tue, 24 Mar 2026 08:04:01 +0530 X-Gm-Features: AaiRm52q1HMpixERVTb1jD5FwaX0DsZZFkRvyuVm9-vasR4pGOMi1PRfF9YNpIE Message-ID: Subject: Re: [BUG] CRASH: ECPGprepared_statement() and ECPGdeallocate_all() when connection is NULL To: Shruthi Gowda Cc: Fujii Masao , Tom Lane , PostgreSQL Development Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 19 Jan 2026 at 17:38, Shruthi Gowda wrote: > > > > On Thu, Jan 8, 2026 at 9:32=E2=80=AFPM Fujii Masao wrote: >> >> On Thu, Jan 8, 2026 at 3:00=E2=80=AFAM Shruthi Gowda wrote: >> > >> > >> > On Mon, Dec 8, 2025 at 9:39=E2=80=AFPM Tom Lane wr= ote: >> >> >> >> Shruthi Gowda writes: >> >> > The ECPG application crashes with a segmentation fault when calling >> >> > specific deallocation or prepared statement functions without an >> >> > established database connection. This is caused by a missing NULL c= heck on >> >> > the connection handle before attempting to access it. >> >> >> >> Hmm ... poking around, I see several other places that aren't checkin= g >> >> the result of ecpg_get_connection. Shouldn't we tighten them all? >> >> >> >> regards, tom lane >> > >> > >> > I agree. I=E2=80=99ve reviewed all occurrences of ecpg_get_connection(= ) and noted that, in most instances, it is followed by ecpg_init(), which v= alidates the connection and returns immediately if the connection is NULL. >> >> Why did you add this check instead of calling ecpg_init()? >> Wouldn't it be better and sufficient to use ecpg_init() to validate >> the connection? >> >> + con =3D ecpg_get_connection(connection_name); >> + if (!con) >> + { >> + ecpg_raise(lineno, ECPG_NO_CONN, ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXI= ST, >> + connection_name ? connection_name : ecpg_gettext("NULL")); >> > > Thanks for the feedback, Fujii. I agree=E2=80=94using ecpg_init() is a m= ore consistent approach and aligns with how this is handled in other parts = of the code. > I have updated the patch to use ecpg_init() for validation. Please find t= he revised version attached. > The patch works for MASTER and all the back branches. > > Thanks & Regards, > > Shruthi K C > > EnterpriseDB: http://www.enterprisedb.com Thanks Shruthi for the updated patch. Please add a crash test case in your patch. If possible, please add a test for connection=3DNULL for ECPGdeallocate_all, ECPGprepared_statement and ECPGget_desc. --=20 Thanks and Regards Mahendra Singh Thalor EnterpriseDB: http://www.enterprisedb.com