Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 0203FB5DBBE for ; Tue, 30 Aug 2011 15:21:17 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 62679-03 for ; Tue, 30 Aug 2011 18:21:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from exprod7og127.obsmtp.com (exprod7og127.obsmtp.com [64.18.2.210]) by mail.postgresql.org (Postfix) with ESMTP id 26E8DB5D803 for ; Tue, 30 Aug 2011 15:21:08 -0300 (ADT) Received: from mail-fx0-f52.google.com ([209.85.161.52]) (using TLSv1) by exprod7ob127.postini.com ([64.18.6.12]) with SMTP ID DSNKTl0qFDO8VyN9hiR84UMvZA7N3WA6lQ8w@postini.com; Tue, 30 Aug 2011 11:21:09 PDT Received: by fxd18 with SMTP id 18so5273258fxd.25 for ; Tue, 30 Aug 2011 11:21:07 -0700 (PDT) Received: by 10.223.6.135 with SMTP id 7mr3924678faz.42.1314728466924; Tue, 30 Aug 2011 11:21:06 -0700 (PDT) Received: from [192.168.1.183] (dsl-hkibrasgw2-ff7ac300-240.dhcp.inet.fi [88.195.122.240]) by mx.google.com with ESMTPS id b13sm4782122fak.16.2011.08.30.11.21.05 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 30 Aug 2011 11:21:05 -0700 (PDT) Message-ID: <4E5D2A0F.4040302@enterprisedb.com> Date: Tue, 30 Aug 2011 21:21:03 +0300 From: Heikki Linnakangas User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; fi-FI; rv:1.9.2.20) Gecko/20110820 Icedove/3.1.12 MIME-Version: 1.0 To: Isaac Jurado CC: pgsql-bugs@postgresql.org Subject: Re: BUG #6185: Segmentation fault with NULL string columns References: <201108300851.p7U8ptkf014277@wwwmaster.postgresql.org> In-Reply-To: <201108300851.p7U8ptkf014277@wwwmaster.postgresql.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201108/191 X-Sequence-Number: 31003 On 30.08.2011 11:51, Isaac Jurado wrote: > > The following bug has been logged online: > > Bug reference: 6185 > Logged by: Isaac Jurado > Email address: ijurado@econcept.es > PostgreSQL version: 8.4.8 > Operating system: Ubuntu 10.04.03 LTS (x86_64) > Description: Segmentation fault with NULL string columns > Details: > > Here's the script to make it fail: > > CREATE DATABASE killme; > \c killme > CREATE FUNCTION to_ascii(bytea, name) RETURNS text AS 'to_ascii_encname' > LANGUAGE internal; > CREATE TABLE mytable (id INTEGER PRIMARY KEY, mytext TEXT); > INSERT INTO mytable (id, mytext) VALUES (1, ''); > SELECT * FROM mytable WHERE to_ascii(convert_to(mytext, 'latin1'), 'latin1') > = to_ascii(convert_to('nicetry', 'latin1'), 'latin1'); > UPDATE mytable SET mytext=NULL WHERE id=1; > SELECT * FROM mytable WHERE to_ascii(convert_to(mytext, 'latin1'), 'latin1') > = to_ascii(convert_to('nicetry', 'latin1'), 'latin1'); > > After the second query, the database server segfaults. Note that it only > fails for NULL values. The to_ascii/convert_to combination is a recipe for > diacritics elimination found on a PostgreSQL forum. to_ascii_encname is marked as STRICT, which means that it returns NULL on NULL input, without ever calling the underlying C function. The "to_ascii" function that you created is not marked as STRICT, so the to_ascii_encname C function is called on NULL input. It's not prepared for that, and crashes, because it's not supposed to be called on NULL input. Why do you create your own 'internal' language function like that in the first place? Just use the existing to_ascii function. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com