coalesce in execute crashes backend

Started by PostgreSQL Bugs Listalmost 25 years ago4 messagesbugs
Jump to latest
#1PostgreSQL Bugs List
pgsql-bugs@postgresql.org

Vinod Kurup (vkurup@massmed.org) reports a bug with a severity of 3
The lower the number the more severe it is.

Short Description
coalesce in execute crashes backend

Long Description
When I use a coalesce statement to calculate an expression that is part of a dynamic query, it crashes the backend. Interestingly, it works if I use constants as arguments to coalesce.

Sample Code
select version();

create function vk_test()
returns integer as '
declare
v_id integer;
begin
v_id := 2;

raise notice ''try a constant.'';
execute ''select '' || coalesce(2,0) || '';'';

raise notice ''that worked'';

raise notice ''now, try a var with the same value.'';
execute ''select '' || coalesce(v_id,0) || '';'';

raise notice ''we never get here'';
return 0;
end;' language 'plpgsql';

select vk_test();

version
-------------------------------------------------------------
PostgreSQL 7.1 on i586-pc-linux-gnu, compiled by GCC 2.95.3
(1 row)

CREATE
psql:junk.sql:24: NOTICE: try a constant.
psql:junk.sql:24: NOTICE: that worked
psql:junk.sql:24: NOTICE: now, try a var with the same value.
psql:junk.sql:24: pqReadData() -- backend closed the channel unexpectedly.
This probably means the backend terminated abnormally
before or while processing the request.
psql:junk.sql:24: connection to server was lost

server.log:
NOTICE: try a constant.
NOTICE: that worked
NOTICE: now, try a var with the same value.
Server process (pid 7516) exited with status 11 at Tue Jun 12 14:32:13 2001
Terminating any active server processes...
NOTICE: Message from PostgreSQL backend:
The Postmaster has informed me that some other backend died abnormally and possibly corrupted shared memory.
I have rolled back the current transaction and am going to terminate your database system connection and exit.
Please reconnect to the database system and repeat your query.

No file was uploaded with this report

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: PostgreSQL Bugs List (#1)
Re: coalesce in execute crashes backend

pgsql-bugs@postgresql.org writes:

coalesce in execute crashes backend

Try the attached patch to 7.1.2. I see Jan's already fixed this in
current sources, but not in the 7.1 branch ...

regards, tom lane

*** src/pl/plpgsql/src/pl_exec.c.orig	Mon May  7 21:02:03 2001
--- src/pl/plpgsql/src/pl_exec.c	Tue Jun 12 21:02:59 2001
***************
*** 3,9 ****
   *			  procedural language
   *
   * IDENTIFICATION
!  *	  $Header: /home/projects/pgsql/cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.41.2.1 2001/05/08 01:02:03 tgl Exp $
   *
   *	  This software is copyrighted by Jan Wieck - Hamburg.
   *
--- 3,9 ----
   *			  procedural language
   *
   * IDENTIFICATION
!  *	  $Header: /home/projects/pgsql/cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.41.2.2 2001/06/13 01:02:59 tgl Exp $
   *
   *	  This software is copyrighted by Jan Wieck - Hamburg.
   *
***************
*** 1922,1930 ****
  								   ObjectIdGetDatum(typeStruct->typelem),
  											 Int32GetDatum(-1)));

- if (!typeStruct->typbyval)
- pfree((void *) query);
-
ReleaseSysCache(typetup);

  	/*
--- 1922,1927 ----
***************
*** 2037,2045 ****
  											 query,
  								   ObjectIdGetDatum(typeStruct->typelem),
  											 Int32GetDatum(-1)));
- 
- 	if (!typeStruct->typbyval)
- 		pfree((void *) query);

ReleaseSysCache(typetup);

--- 2034,2039 ----
#3Vinod Kurup
vkurup@massmed.org
In reply to: Tom Lane (#2)
Re: coalesce in execute crashes backend

On Tue, Jun 12, 2001 at 09:06:17PM -0400, Tom Lane wrote:

pgsql-bugs@postgresql.org writes:

coalesce in execute crashes backend

Try the attached patch to 7.1.2. I see Jan's already fixed this in
current sources, but not in the 7.1 branch ...

Excellent!! That fixed it.

Will this fix then be placed in the next 7.1.x release as well?

Thanks,

Vinod

--
_____________________________
Vinod Kurup, MD
email: vkurup@massmed.org
phone: 617.277.2012
cell: 617.359.5990
http://www.kurup.com
aim: vvkurup

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Vinod Kurup (#3)
Re: coalesce in execute crashes backend

Vinod Kurup <vkurup@massmed.org> writes:

Will this fix then be placed in the next 7.1.x release as well?

Yes, if there is one.

regards, tom lane