Author: timbo
Date: Thu Dec  6 02:48:17 2007
New Revision: 10378

Modified:
   dbi/trunk/Changes
   dbi/trunk/DBI.xs
   dbi/trunk/Driver.xst
   dbi/trunk/Driver_xst.h

Log:
Fixed potential coredump if stack reallocated while calling back into perl from 
XS code. Thanks to John Gardiner Myers.


Modified: dbi/trunk/Changes
==============================================================================
--- dbi/trunk/Changes   (original)
+++ dbi/trunk/Changes   Thu Dec  6 02:48:17 2007
@@ -42,6 +42,8 @@
 
 =head2 Changes in DBI ...
 
+  Fixed potential coredump if stack reallocated while calling back
+    into perl from XS code. Thanks to John Gardiner Myers.
   Fixed DBI::Util::CacheMemory->new to not clear the cache.
   Expanded DBI::DBD docs for driver authors thanks to Martin Evans.
   Enhanced t/80proxy.t test script.

Modified: dbi/trunk/DBI.xs
==============================================================================
--- dbi/trunk/DBI.xs    (original)
+++ dbi/trunk/DBI.xs    Thu Dec  6 02:48:17 2007
@@ -4276,6 +4276,7 @@
        }
        PUSHMARK(mark);  /* reset mark (implies one arg as we were called with 
one arg?) */
        perl_call_sv((SV*)GvCV(imp_gv), GIMME);
+        SPAGAIN;
 #ifdef DBI_save_hv_fetch_ent
        PL_hv_fetch_ent_mh = save_mh;
 #endif
@@ -4617,6 +4618,7 @@
     XPUSHs(sth);
     PUTBACK;
     num_fields = perl_call_method("fetchrow", G_ARRAY);        /* XXX change 
the name later */
+    SPAGAIN;
     if (num_fields == 0) {
        ST(0) = &sv_undef;
     } else {

Modified: dbi/trunk/Driver.xst
==============================================================================
--- dbi/trunk/Driver.xst        (original)
+++ dbi/trunk/Driver.xst        Thu Dec  6 02:48:17 2007
@@ -111,7 +111,9 @@
                (DBD_ATTRIB_TRUE(attr,"Slice",5,tmp_svp) || 
DBD_ATTRIB_TRUE(attr,"Columns",7,tmp_svp))
        ) {
            /* fallback to perl implementation */
-           ST(0) 
=dbixst_bounce_method("DBD::~DRIVER~::db::SUPER::selectall_arrayref", items);
+           SV *tmp 
=dbixst_bounce_method("DBD::~DRIVER~::db::SUPER::selectall_arrayref", items);
+           SPAGAIN;
+           ST(0) = tmp;
            XSRETURN(1);
        }
     }
@@ -380,9 +382,13 @@
      * would be &sv_undef for error or an SV holding the imp_data.
      */
     SV *sv = dbd_take_imp_data(h, imp_xxh, NULL);
-    ST(0) = (SvOK(sv) && !SvTRUE(sv))
-       ? dbixst_bounce_method("DBD::~DRIVER~::db::SUPER::take_imp_data", items)
-       : sv_2mortal(sv);
+    if (SvOK(sv) && !SvTRUE(sv)) {
+       SV *tmp = 
dbixst_bounce_method("DBD::~DRIVER~::db::SUPER::take_imp_data", items);
+       SPAGAIN;
+       ST(0) = tmp;
+    } else {
+       ST(0) = sv_2mortal(sv);
+    }
 
 #endif
 
@@ -630,7 +636,9 @@
     SV *       batch_row_count
     CODE:
     if (SvOK(slice)) {  /* fallback to perl implementation */
-        ST(0) = 
dbixst_bounce_method("DBD::~DRIVER~::st::SUPER::fetchall_arrayref", 3);
+       SV *tmp = 
dbixst_bounce_method("DBD::~DRIVER~::st::SUPER::fetchall_arrayref", 3);
+       SPAGAIN;
+        ST(0) = tmp;
     }
     else {
        ST(0) = dbdxst_fetchall_arrayref(sth, slice, batch_row_count);

Modified: dbi/trunk/Driver_xst.h
==============================================================================
--- dbi/trunk/Driver_xst.h      (original)
+++ dbi/trunk/Driver_xst.h      Thu Dec  6 02:48:17 2007
@@ -11,6 +11,7 @@
  * It would be better if we setup perl's context so SUPER:: did the right thing
  * (borrowing the relevant magic from pp_entersub in perl pp_hot.c).
  * Then we could just use call_method("SUPER::foo") instead.
+ * XXX remember to call SPAGAIN in the calling code after calling this!
  */
 static SV *
 dbixst_bounce_method(char *methname, int params)

Reply via email to