Skip Menu |

This queue is for tickets about the DBD-DB2 CPAN distribution.

Report information
The Basics
Id: 22150
Status: resolved
Priority: 0/
Queue: DBD-DB2

People
Owner: Nobody in particular
Requestors: GAAS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.80
Fixed in: (no value)



Subject: Segfault for multiple result set
The attached program returning results from the sample database segfaults. I'm currently using DBI-1.48, DBD::DB2-0.80 and perl-5.8.7. I'm running on Linux. gdb perl GNU gdb 6.4 Copyright 2005 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i686-pc-linux-gnu"...(no debugging symbols found) Using host libthread_db library "/lib/libthread_db.so.1". Show quoted text
gdb> run db2-segfault.pl
(no debugging symbols found) (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) [Thread debugging using libthread_db enabled] [New Thread -1210214208 (LWP 4129)] FETCH... Sanders Pernal James Sneider FETCH... Program received signal SIGSEGV, Segmentation fault. [Switching to Thread -1210214208 (LWP 4129)] Error while running hook_stop: Invalid type combination in ordering comparison. 0xb7d9e1d7 in dbih_get_fbav () from /opt/perl/apee548/lib/site_perl/5.8.7/i686-linux-thread-multi/auto/DBI/DBI.so Show quoted text
gdb> bt
#0 0xb7d9e1d7 in dbih_get_fbav () from /opt/perl/apee548/lib/site_perl/5.8.7/i686-linux-thread-multi/auto/DBI/DBI.so #1 0xb7d901a3 in db2_st_fetch () from /opt/perl/apee548/lib/site_perl/5.8.7/i686-linux-thread-multi/auto/DBD/DB2/DB2.so #2 0xb7d86acd in XS_DBD__DB2__st_fetchrow_array () from /opt/perl/apee548/lib/site_perl/5.8.7/i686-linux-thread-multi/auto/DBD/DB2/DB2.so #3 0xb7da4cdf in XS_DBI_dispatch () from /opt/perl/apee548/lib/site_perl/5.8.7/i686-linux-thread-multi/auto/DBI/DBI.so #4 0x080b5603 in Perl_pp_entersub () #5 0x080aee01 in Perl_runops_standard () #6 0x0806376d in S_run_body () #7 0x08063466 in perl_run () #8 0x0805ff79 in main ()
Subject: db2-segfault.pl
use strict; use DBI; my $dbh = DBI->connect("dbi:DB2:sample","","") || die "$DBI::dberr"; $dbh->do("drop procedure foo"); $dbh->do(<<EOT); create procedure foo language sql BEGIN declare tab1 cursor with return to client for SELECT * FROM staff; declare tab2 cursor with return to client for SELECT name FROM staff WHERE dept = 20; open tab2; open tab1; END EOT my $sth = $dbh->prepare("call foo"); $sth->execute || die; do { print "FETCH...\n"; while (my @row = $sth->fetchrow) { printf "@row\n"; } } while ($sth->{db2_more_results});
This seems to be a problem in DBI itself. It assumes that the number of fields stays constant for a statement handle, so it ends up dereferencing outside of the array if later results set have more rows. Attached patch is a fix.
Fix segfault for multiple result sets when later sets grow more fields. DBI assumes the number of fields stay the same for a statement handle. Ref http://rt.cpan.org/Ticket/Display.html?id=22150 Index: DBI.xs --- DBI.xs.~1~ Wed Oct 18 11:40:48 2006 +++ DBI.xs Wed Oct 18 11:40:48 2006 @@ -1370,9 +1370,9 @@ if ( (av = DBIc_FIELDS_AV(imp_sth)) == Nullav) av = dbih_setup_fbav(imp_sth); - - if (1) { /* XXX turn into option later */ - int i = DBIc_NUM_FIELDS(imp_sth); + else { /* XXX turn into option later */ + dTHX; + int i = av_len(av) + 1; /* don't let SvUTF8 flag persist from one row to the next */ /* (only affects drivers that use sv_setpv, but most XS do) */ while(i--) /* field 1 stored at index 0 */ End of Patch.
"This seems to be a problem in DBI itself. It assumes that the number of fields stays constant for a statement handle" -- actually the driver is meant to update DBIc_NUM_FIELDS(imp_sth) to match the number of fields in the current result set. The proposed patch is good (I've applied something similar for DBI 1.53), but it only addresses a symptom not the cause. There are likely to be other problems.
This bug has been found to be in an earlier version DBI itself and not in the DBD::DB2 module and is therefore being closed.