pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #6185: Segmentation fault with NULL string columns
5+ messages / 3 participants
[nested] [flat]

* BUG #6185: Segmentation fault with NULL string columns
@ 2011-08-30 08:51  Isaac Jurado <ijurado@econcept.es>
  0 siblings, 2 replies; 5+ messages in thread

From: Isaac Jurado @ 2011-08-30 08:51 UTC (permalink / raw)
  To: pgsql-bugs


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.



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #6185: Segmentation fault with NULL string columns
@ 2011-08-30 18:21  Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
  parent: Isaac Jurado <ijurado@econcept.es>
  1 sibling, 1 reply; 5+ messages in thread

From: Heikki Linnakangas @ 2011-08-30 18:21 UTC (permalink / raw)
  To: Isaac Jurado <ijurado@econcept.es>; +Cc: pgsql-bugs

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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #6185: Segmentation fault with NULL string columns
@ 2011-08-30 18:22  Alvaro Herrera <alvherre@commandprompt.com>
  parent: Isaac Jurado <ijurado@econcept.es>
  1 sibling, 1 reply; 5+ messages in thread

From: Alvaro Herrera @ 2011-08-30 18:22 UTC (permalink / raw)
  To: Isaac Jurado <ijurado@econcept.es>; +Cc: pgsql-bugs

Excerpts from Isaac Jurado's message of mar ago 30 05:51:55 -0300 2011:
> 
> 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;

Seems you neglected to mark the function STRICT.

-- 
Álvaro Herrera <alvherre@commandprompt.com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #6185: Segmentation fault with NULL string columns
@ 2011-08-30 18:53  Isaac Jurado <ijurado@econcept.es>
  parent: Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Isaac Jurado @ 2011-08-30 18:53 UTC (permalink / raw)
  To: Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>; +Cc: pgsql-bugs

On Tue, Aug 30, 2011 at 8:21 PM, Heikki Linnakangas
<heikki.linnakangas@enterprisedb.com> wrote:
>
> 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.

I figured that 5 minutes after reporting.  I tried to sent a reply email
but it seems it didn't arrive.  Thanks anyway.

> Why do you create your own 'internal' language function like that in
> the first place? Just use the existing to_ascii function.

The default to_ascii expects a string as a first argument.  As our DB
encoding is UTF8 we need to filter everything through
convert_to(..., 'LATIN1').  Because convert_to function returns a
"bytea" type, we cannot use to_ascii in vanilla flavour.

We are not too fond with the PostgreSQL specifics (although the explicit
::text cast didn't work), so we found that function definition on a
wiki and it worked.

But now, unless you know a more correct way to do it, it works like a
charm by appending "STRICT" to the function definition.

Best regards and sorry for the noise.

-- 
Isaac Jurado
Internet Busines Solutions eConcept



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #6185: Segmentation fault with NULL string columns
@ 2011-08-30 18:54  Isaac Jurado <ijurado@econcept.es>
  parent: Alvaro Herrera <alvherre@commandprompt.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Isaac Jurado @ 2011-08-30 18:54 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@commandprompt.com>; +Cc: pgsql-bugs

On Tue, Aug 30, 2011 at 8:22 PM, Alvaro Herrera
<alvherre@commandprompt.com> wrote:
>
> Seems you neglected to mark the function STRICT.

Yes, that was it.  Sorry for the invalid bug report.

Best regards.

-- 
Isaac Jurado
Internet Busines Solutions eConcept



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2011-08-30 18:54 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-08-30 08:51 BUG #6185: Segmentation fault with NULL string columns Isaac Jurado <ijurado@econcept.es>
2011-08-30 18:21 ` Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
2011-08-30 18:53   ` Isaac Jurado <ijurado@econcept.es>
2011-08-30 18:22 ` Alvaro Herrera <alvherre@commandprompt.com>
2011-08-30 18:54   ` Isaac Jurado <ijurado@econcept.es>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox