Обсуждение: Syntax error in plpgsql crashes backend
I've found a pathological function input that crashes the backend. Note the profusion of 'blah' text and the lack of an 'end;' statement. Less text or an end statement stops this function from provoking a crash. CREATE OR REPLACE FUNCTION foo() RETURNS INTEGER AS ' DECLAREquerystr TEXT; BEGIN querystr := '' -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blahblah blah blah blah blah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blahblah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blah blah blahblah blah blah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blahblah blah blah blah blah blah blah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blah blah blah blah blahblah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blahblah blah blah blah blah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blahblah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blah blah blahblah blah blah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blahblah blah blah blah blah blah blah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blah blah blah blah blahblah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blahblah blah blah blah blah blah ''; return 1; ' language 'plpgsql'; When I load this function and try to execute it, I get a syntax error: cal=> \i test CREATE cal=> select foo(); NOTICE: plpgsql: ERROR during compile of foo near line 60 ERROR: parse error at or near "" If I try it again, the backend crashes: cal=> select foo(); NOTICE: plpgsql: ERROR during compile of foo near line 60 ERROR: parse error at or near "" pqReadData() -- backend closed the channel unexpectedly.This probably means the backend terminated abnormallybefore or whileprocessing the request. The connection to the server was lost. Attempting reset: Failed. !> I get the following output from the postmaster: ERROR: parse error at or near "" NOTICE: plpgsql: ERROR during compile of foo near line 60 DEBUG: server process (pid 17990) was terminated by signal 11 DEBUG: terminating any other active server processes DEBUG: all server processes terminated; reinitializing shared memory and semaphores DEBUG: database system was interrupted at 2002-05-04 14:03:46 EDT DEBUG: checkpoint record is at 0/41FFA70 DEBUG: redo record is at 0/41FFA70; undo record is at 0/0; shutdown TRUE DEBUG: next transaction id: 41659; next oid: 147628 DEBUG: database system was not properly shut down; automatic recovery in progress DEBUG: redo starts at 0/41FFAB0 DEBUG: ReadRecord: record with zero length at 0/4205D4C DEBUG: redo done at 0/4205D28 FATAL 1: The database system is starting up DEBUG: database system is ready I anticipate that the correct response is `Don't do that then!' But I assume someone would want to know about crashes like this. I'm using PostgreSQL 7.2, compiled with `gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-85)' --Joe
More fun with the backend: I've found that I can incite a crash by reloading a long, but syntactically correct function twice. Is this a problem with my installation? --Joe cal=> \i test CREATE cal=> select foo();foo ----- 1 (1 row) cal=> \i test CREATE cal=> select foo(); pqReadData() -- backend closed the channel unexpectedly.This probably means the backend terminated abnormallybefore or whileprocessing the request. The connection to the server was lost. Attempting reset: Failed. !> On the console: DEBUG: server process (pid 18109) was terminated by signal 11 DEBUG: terminating any other active server processes DEBUG: all server processes terminated; reinitializing shared memory and semaphores DEBUG: database system was interrupted at 2002-05-04 14:18:31 EDT DEBUG: checkpoint record is at 0/424D570 DEBUG: redo record is at 0/424D570; undo record is at 0/0; shutdown TRUE DEBUG: next transaction id: 41770; next oid: 164012 DEBUG: database system was not properly shut down; automatic recovery in progress FATAL 1: The database system is starting up DEBUG: redo starts at 0/424D5B0 DEBUG: ReadRecord: record with zero length at 0/4253914 DEBUG: redo done at 0/42538F0 DEBUG: database system is ready Function body: CREATE OR REPLACE FUNCTION foo() RETURNS INTEGER AS ' DECLAREquerystr TEXT; BEGIN querystr := '' -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blahblah blah blah blah blah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blahblah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blah blah blahblah blah blah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blahblah blah blah blah blah blah blah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blah blah blah blah blahblah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blahblah blah blah blah blah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blahblah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blah blah blahblah blah blah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blahblah blah blah blah blah blah blah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blah blah blah blah blahblah blah -- blah blah blah blah blah blah blah blah blah blah blah -- blah blah blah blah blahblah blah blah blah blah blah ''; return 1; end; ' language 'plpgsql';
On Sat, May 04, 2002 at 02:19:35PM -0400, Joseph Barillari wrote: | More fun with the backend: I've found that I can incite a crash by | reloading a long, but syntactically correct function twice. Is this a | problem with my installation? --Joe Considering that you said postgres was built with gcc 2.96 I really wouldn't be surprised. http://gcc.gnu.org/gcc-2.96.html Try using a real compiler and see if the problem still exists :-). -D -- Pleasant words are a honeycomb, sweet to the soul and healing to the bones. Proverbs 16:24 GnuPG key : http://dman.ddts.net/~dman/public_key.gpg
>>>>> "d" == dman <dman@dman.ddts.net> writes: > On Sat, May 04, 2002 at 02:19:35PM -0400, Joseph Barillari > wrote: | More fun with the backend: I've found that Ican incite > a crash by | reloading a long, but syntactically correct > function twice. Is this a | problem with myinstallation? --Joe > Considering that you said postgres was built with gcc 2.96 I > really wouldn't be surprised. > http://gcc.gnu.org/gcc-2.96.html > Try using a real compiler and see if the problem still exists > :-). > -D I tried it on a Debian box with 2.95 (version 2.95.4 20011002 (Debian prerelease)) and had the same problem. --Joe
On Sat, May 04, 2002 at 02:19:35PM -0400, Joseph Barillari wrote: > More fun with the backend: I've found that I can incite a crash by > reloading a long, but syntactically correct function twice. Is this a > problem with my installation? --Joe <snip> I created Joseph's function here and the my backend also crashes. foobar=# select version(); version ---------------------------------------------------------------PostgreSQL 7.2.1 on i686-pc-linux-gnu, compiled by GCC 2.95.4 -Roberto -- +----| http://fslc.usu.edu/ USU Free Software & GNU/Linux Club |------+ Roberto Mello - Computer Science, USU - http://www.brasileiro.net/ http://www.sdl.usu.edu/ - Space Dynamics Lab, Developer Homework time limit exceeded. Auto logon in effect!
I just tried this on current sources and it was fine: test=> select version(); version ----------------------------------------------------------------PostgreSQL 7.3devel on i386-pc-bsdi4.2, compiled by GCC 2.95.2 (1 row) --------------------------------------------------------------------------- Roberto Mello wrote: > On Sat, May 04, 2002 at 02:19:35PM -0400, Joseph Barillari wrote: > > More fun with the backend: I've found that I can incite a crash by > > reloading a long, but syntactically correct function twice. Is this a > > problem with my installation? --Joe > > <snip> > > I created Joseph's function here and the my backend also crashes. > > foobar=# select version(); > version > --------------------------------------------------------------- > PostgreSQL 7.2.1 on i686-pc-linux-gnu, compiled by GCC 2.95.4 > > -Roberto > > -- > +----| http://fslc.usu.edu/ USU Free Software & GNU/Linux Club |------+ > Roberto Mello - Computer Science, USU - http://www.brasileiro.net/ > http://www.sdl.usu.edu/ - Space Dynamics Lab, Developer > Homework time limit exceeded. Auto logon in effect! > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/users-lounge/docs/faq.html > -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 853-3000+ If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania19026
IIRC, a gentleman whose name escapes me fixed this in CVS -- the problem was that the PL/pgsql handler wasn't grabbing enough memory. The current devel sources should reflect the fix. --Joe On Mon, 3 Jun 2002, Bruce Momjian wrote: > > I just tried this on current sources and it was fine: > > test=> select version(); > version > ---------------------------------------------------------------- > PostgreSQL 7.3devel on i386-pc-bsdi4.2, compiled by GCC 2.95.2 > (1 row) > > > --------------------------------------------------------------------------- > > Roberto Mello wrote: > > On Sat, May 04, 2002 at 02:19:35PM -0400, Joseph Barillari wrote: > > > More fun with the backend: I've found that I can incite a crash by > > > reloading a long, but syntactically correct function twice. Is this a > > > problem with my installation? --Joe > > > > <snip> > > > > I created Joseph's function here and the my backend also crashes. > > > > foobar=# select version(); > > version > > --------------------------------------------------------------- > > PostgreSQL 7.2.1 on i686-pc-linux-gnu, compiled by GCC 2.95.4 > > > > -Roberto > > > > -- > > +----| http://fslc.usu.edu/ USU Free Software & GNU/Linux Club |------+ > > Roberto Mello - Computer Science, USU - http://www.brasileiro.net/ > > http://www.sdl.usu.edu/ - Space Dynamics Lab, Developer > > Homework time limit exceeded. Auto logon in effect! > > > > ---------------------------(end of broadcast)--------------------------- > > TIP 5: Have you checked our extensive FAQ? > > > > http://www.postgresql.org/users-lounge/docs/faq.html > > > > -- > Bruce Momjian | http://candle.pha.pa.us > pgman@candle.pha.pa.us | (610) 853-3000 > + If your life is a hard drive, | 830 Blythe Avenue > + Christ can be your backup. | Drexel Hill, Pennsylvania 19026 >