BUG #9202: C Functions crash database too easily

From: rotten(at)windfish(dot)net
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #9202: C Functions crash database too easily
Date: 2014-02-12 20:53:02
Message-ID: 20140212205302.2708.53160@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 9202
Logged by: Rick Otten
Email address: rotten(at)windfish(dot)net
PostgreSQL version: 9.3.2
Operating system: Ubuntu 12.04
Description:

While setting up a third party (commerical) provided C library functions
I've observed PostgreSQL 9.3.2 to be very sensitive to simple typos.

1) If you create the function with a different number of arguments than the
C function expects, the create works just fine. However, every time you do
a select, the database chokes:

2014-02-11 13:03:27.989 EST mydb [local] postgresLOG: statement: create
function myschema.my_6_argument_function(character, character, character,
character, character)
returns character as '/some/path/lib/some.so', 'My_6_Arg_Function'
LANGUAGE C STRICT;
...
2014-02-11 13:03:33.919 EST LOG: server process (PID 9090) was terminated
by signal 11: Segmentation fault
2014-02-11 13:03:33.920 EST DETAIL: Failed process was running: select
myschema.my_6_argument_function('arg1', 'arg2', 'arg3', 'arg4', 'arg5');
2014-02-11 13:03:33.920 EST LOG: terminating any other active server
processes
2014-02-11 13:03:33.922 EST [unknown] [unknown]LOG: connection received:
host=[local]
2014-02-11 13:03:33.922 EST mydb [local] postgresFATAL: the database system
is in recovery mode
2014-02-11 13:03:33.929 EST WARNING: terminating connection because of
crash of another server process
2014-02-11 13:03:33.929 EST DETAIL: The postmaster has commanded this
server process to roll back the current transaction and exit, because
another server process exited abnormally and possibly corrupted shared
memory.
2014-02-11 13:03:33.929 EST HINT: In a moment you should be able to
reconnect to the database and repeat your command.
2014-02-11 13:03:33.933 EST LOG: all server processes terminated;
reinitializing
2014-02-11 13:03:34.061 EST LOG: database system was interrupted; last
known up at 2014-02-11 13:02:37 EST
2014-02-11 13:03:34.061 EST LOG: database system was not properly shut
down; automatic recovery in progress
2014-02-11 13:03:34.066 EST LOG: redo starts at 10/203C360
2014-02-11 13:03:34.067 EST LOG: record with zero length at 10/20433C8
2014-02-11 13:03:34.067 EST LOG: redo done at 10/2043398
2014-02-11 13:03:34.067 EST LOG: last completed transaction was at log
time 2014-02-11 13:03:27.994445-05
2014-02-11 13:03:34.101 EST LOG: autovacuum launcher started
2014-02-11 13:03:34.101 EST LOG: database system is ready to accept
connections

2) The same thing happens if you try to create the same function twice:

2014-02-12 15:20:45.626 EST mydb [local] postgresLOG: statement: create
function
myschema.myfunction(character, character)
returns
character as '/some/path/somelib', 'MY_Function'
LANGUAGE C STRICT;
2014-02-12 15:20:45.626 EST mydb [local] postgresWARNING: using index
"pg_event_trigger_evtname_index" despite IgnoreSystemIndexes
2014-02-12 15:20:45.627 EST mydb [local] postgresPANIC: function
"myfunction" already exists with same argument types
2014-02-12 15:20:45.627 EST mydb [local] postgresSTATEMENT: create
function
myschema.myfunction(character, character)
returns
character as '/some/path/somelib', 'My_Function'
LANGUAGE C STRICT;
2014-02-12 15:20:45.768 EST LOG: server process (PID 2316) was terminated
by signal 6: Aborted
2014-02-12 15:20:45.768 EST DETAIL: Failed process was running: create
function
myschema.myfunction(character, character)
returns
character as '/some/path/somelib', 'MY_Function'
LANGUAGE C STRICT;
2014-02-12 15:20:45.768 EST LOG: terminating any other active server
processes
2014-02-12 15:20:45.777 EST [unknown] [unknown]LOG: connection received:
host=[local]
2014-02-12 15:20:45.778 EST mydb [local] postgresFATAL: the database system
is in recovery mode
2014-02-12 15:20:45.778 EST WARNING: terminating connection because of
crash of another server process
2014-02-12 15:20:45.778 EST DETAIL: The postmaster has commanded this
server process to roll back the current transaction and exit, because
another server process exited abnormally and possibly corrupted shared
memory.
2014-02-12 15:20:45.778 EST HINT: In a moment you should be able to
reconnect to the database and repeat your command.
2014-02-12 15:20:45.783 EST LOG: all server processes terminated;
reinitializing
2014-02-12 15:20:45.926 EST LOG: database system was interrupted; last
known up at 2014-02-12 07:05:01 EST
2014-02-12 15:20:45.927 EST LOG: database system was not properly shut
down; automatic recovery in progress
2014-02-12 15:20:45.934 EST LOG: record with zero length at 10/4000090
2014-02-12 15:20:45.934 EST LOG: redo is not required
2014-02-12 15:20:45.968 EST LOG: autovacuum launcher started
2014-02-12 15:20:45.969 EST LOG: database system is ready to accept
connections

For case (1) I think you shouldn't be able to create a C function without
the right number of arguments. Or at least if you do a select, instead of
crashing the database, PostgreSQL should catch the error and reports it.

For case (2) accidentally creating an object with the same name as an
existing object seems like a regular sort of thing that could happen. It
shouldn't crash the database when the name collision occurs.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message pythonesque 2014-02-13 02:44:15 BUG #9204: truncate_identifier may be called unnecessarily on escaped quoted identifiers
Previous Message Pavel Stehule 2014-02-12 20:21:30 Re: BUG #9187: corrupt toast tables