I spend many hours tracking down a segfault in a perl script that made a DBI connection to a PostgreSQL 7.4 server. I'm posting this just to raise the awareness level of a problem that hasn't been addressed so other people don't have to take the time I did.

Fetching values of some esoteric types causes a null pointer dereference. You can see this yourself by running SELECT conkey FROM pg_constraint if you have some sort of constraint to fetch. The fix is either wait for a new version of DBD::Pg or manually cast the type to something that is handled. SELECT array_to_string(conkey,' ') FROM pg_constraint works.

Here's a list of types from 7.4 that if encountered will break DBD::Pg <= 1.31.

_line, _circle, _money, _bool, _bytea, _char, _name, _int2, _int2vector, _int4, _regproc, _text, _oid, _tid, _xid, _cid, _oidvector, _bpchar, _varchar, _int8, _point, _lseg, _path, _box, _float4, _float8, _abstime, _reltime, _tinterval, _polygon, _aclitem, _macaddr, _inet, _cidr, _timestamp, _date, _time, _timestamptz, _interval, _numeric, _timetz, _bit, _varbit, _refcursor, _regprocedure, _regoper, _regoperator, _regclass, _regtype, anyelement

The following patch also works to fix the null-pointer bug if you felt like doing that as well.

diff -u DBD-Pg-1.31a/dbdimp.c DBD-Pg-1.31b/dbdimp.c --- DBD-Pg-1.31a/dbdimp.c 2003-10-27 13:57:02.000000000 -0600 +++ DBD-Pg-1.31b/dbdimp.c 2004-01-02 20:43:51.000000000 -0600 @@ -1028,7 +1028,9 @@ pg_type = PQftype(imp_sth->result, i); type_info = pg_type_data(pg_type); - + if (dbis->debug >= 2) + PerlIO_printf(DBILOGFP, "pg_type %d ty +pe_info %d\n", pg_type, type_info == NULL); + if (type_info) type_info->dequote(value, &value_len); + /* dequote in place */ else @@ -1036,7 +1038,7 @@ sv_setpvn(sv, value, value_len); - if ((type_info->type_id == BPCHAROID) && chopb +lanks) { + if (type_info && (type_info->type_id == BPCHAR +OID) && chopblanks) { p = SvEND(sv); len = SvCUR(sv); while(len && *--p == ' ')

In reply to Null pointer dereference in DBD::Pg 1.31 with PostgreSQL 7.4 by diotalevi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.