Author: chromatic
Date: Mon May  5 22:14:57 2008
New Revision: 27333

Modified:
   trunk/config/gen/makefiles/root.in
   trunk/src/io/io.c

Log:
[PIO] Made PIO_putps check that the PMC to which to write is sane.  Fixes the
crash in RT #52396, reported by Seneca Cunningham.

Enabled CONST_STRING for src/io/io.c.

Modified: trunk/config/gen/makefiles/root.in
==============================================================================
--- trunk/config/gen/makefiles/root.in  (original)
+++ trunk/config/gen/makefiles/root.in  Mon May  5 22:14:57 2008
@@ -604,6 +604,7 @@
     $(SRC_DIR)/inter_cb.str \
     $(SRC_DIR)/inter_create.str \
     $(SRC_DIR)/inter_misc.str \
+    $(SRC_DIR)/io/io.str \
     $(SRC_DIR)/key.str \
     $(SRC_DIR)/library.str \
     $(SRC_DIR)/mmd.str \

Modified: trunk/src/io/io.c
==============================================================================
--- trunk/src/io/io.c   (original)
+++ trunk/src/io/io.c   Mon May  5 22:14:57 2008
@@ -1,5 +1,5 @@
 /*
-Copyright (C) 2001-2007, The Perl Foundation.
+Copyright (C) 2001-2008, The Perl Foundation.
 $Id$
 
 =head1 NAME
@@ -30,6 +30,7 @@
 
 #include "parrot/parrot.h"
 #include "io_private.h"
+#include "io.str"
 
 #include <stdarg.h>
 
@@ -1038,9 +1039,13 @@
 INTVAL
 PIO_putps(PARROT_INTERP, ARGMOD(PMC *pmc), ARGMOD_NULLOK(STRING *s))
 {
-    ParrotIOLayer * const l = (ParrotIOLayer *)PMC_struct_val(pmc);
-    ParrotIO * const io = (ParrotIO *)PMC_data0(pmc);
-    PARROT_ASSERT((unsigned long)l != 0xdeadbeefUL);
+    ParrotIOLayer * const l  = (ParrotIOLayer *)PMC_struct_val(pmc);
+    ParrotIO      * const io = (ParrotIO *)PMC_data0(pmc);
+
+    if (PMC_IS_NULL(pmc)
+    || !VTABLE_isa(interp, pmc, CONST_STRING(interp, "ParrotIO")))
+        real_exception(interp, NULL, PIO_ERROR, "Cannot put to non-PIO PMC");
+
     PARROT_ASSERT(io);
 
     if (!s)

Reply via email to