Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WDymJ-00015k-5Z for pgsql-bugs@arkaria.postgresql.org; Thu, 13 Feb 2014 16:04:43 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WDymI-0001ym-MO for pgsql-bugs@arkaria.postgresql.org; Thu, 13 Feb 2014 16:04:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WDymI-0001yg-5A for pgsql-bugs@postgresql.org; Thu, 13 Feb 2014 16:04:42 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WDymF-0003t1-Ay for pgsql-bugs@postgresql.org; Thu, 13 Feb 2014 16:04:41 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id s1DG4bE2004290; Thu, 13 Feb 2014 11:04:38 -0500 From: Tom Lane To: rotten@windfish.net cc: pgsql-bugs@postgresql.org Subject: Re: BUG #9202: C Functions crash database too easily In-reply-to: <20140212205302.2708.53160@wrigleys.postgresql.org> References: <20140212205302.2708.53160@wrigleys.postgresql.org> Comments: In-reply-to rotten@windfish.net message dated "Wed, 12 Feb 2014 20:53:02 +0000" Date: Thu, 13 Feb 2014 11:04:37 -0500 Message-ID: <4289.1392307477@sss.pgh.pa.us> X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org rotten@windfish.net writes: > 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. Coding in C in general is very sensitive to simple typos. Perhaps you should use some higher-level PL if you find C too uncooperative. > 2) The same thing happens if you try to create the same function twice: Hm, that seems odd, since merely creating the function doesn't call it. But then again, stuff like this suggests that you're abusing something rather badly: > 2014-02-12 15:20:45.626 EST mydb [local] postgresWARNING: using index > "pg_event_trigger_evtname_index" despite IgnoreSystemIndexes How did IgnoreSystemIndexes come to be set? > 2014-02-12 15:20:45.627 EST mydb [local] postgresPANIC: function > "myfunction" already exists with same argument types Interesting; that should only be an ERROR not a PANIC. I'm guessing that something in your loadable module left the system thinking it was in a critical section, which would cause errors to be promoted to panics like that. In general it looks like these issues arise from your C code having tromped on some global variables it shouldn't have. Wild store through a wrong pointer, perhaps? > For case (1) I think you shouldn't be able to create a C function without > the right number of arguments. I know of no way that we could (portably) infer the number of arguments a C function expects from looking at the loadable library. Even if we could, that alone wouldn't be much of a safety improvement. There are too many other ways to crash things with an incorrect C function. IME wrong data types and failure to handle null arguments properly (neither checking for them explicitly, nor marking the function STRICT) are bigger hazards than wrong-number-of-arguments. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs