[svn:parrot] r44877 - in trunk: src/pmc t/pmc

dukeleto at svn.parrot.org dukeleto at svn.parrot.org
Thu Mar 11 14:38:10 UTC 2010


Author: dukeleto
Date: Thu Mar 11 14:38:10 2010
New Revision: 44877
URL: https://trac.parrot.org/parrot/changeset/44877

Log:
[t][TT#1509] Prevent core dumps by preventing negative length array creation. Tests for FFA, FPA, FIA, FSA and FBA

Modified:
   trunk/src/pmc/fixedbooleanarray.pmc
   trunk/src/pmc/fixedfloatarray.pmc
   trunk/src/pmc/fixedintegerarray.pmc
   trunk/src/pmc/fixedpmcarray.pmc
   trunk/src/pmc/fixedstringarray.pmc
   trunk/t/pmc/fixedbooleanarray.t
   trunk/t/pmc/fixedfloatarray.t
   trunk/t/pmc/fixedintegerarray.t
   trunk/t/pmc/fixedpmcarray.t
   trunk/t/pmc/fixedstringarray.t

Modified: trunk/src/pmc/fixedbooleanarray.pmc
==============================================================================
--- trunk/src/pmc/fixedbooleanarray.pmc	Thu Mar 11 14:24:43 2010	(r44876)
+++ trunk/src/pmc/fixedbooleanarray.pmc	Thu Mar 11 14:38:10 2010	(r44877)
@@ -73,6 +73,10 @@
     VTABLE void init_int(INTVAL size) {
         const size_t size_in_bytes = get_size_in_bytes(size);
 
+        if (size < 0)
+            Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS,
+                _("FixedBooleanArray: Cannot set array size to a negative number (%d)"), size);
+
         SET_ATTR_size(INTERP, SELF, size);
         SET_ATTR_resize_threshold(INTERP, SELF, size_in_bytes * BITS_PER_CHAR);
         SET_ATTR_bit_array(INTERP, SELF, mem_gc_allocate_n_zeroed_typed(INTERP, size_in_bytes,

Modified: trunk/src/pmc/fixedfloatarray.pmc
==============================================================================
--- trunk/src/pmc/fixedfloatarray.pmc	Thu Mar 11 14:24:43 2010	(r44876)
+++ trunk/src/pmc/fixedfloatarray.pmc	Thu Mar 11 14:38:10 2010	(r44877)
@@ -56,9 +56,12 @@
 
 */
 
-    VTABLE void init_int(INTVAL new_size) {
-        SET_ATTR_size(INTERP, SELF, new_size);
-        SET_ATTR_float_array(INTERP, SELF, mem_gc_allocate_n_typed(INTERP, new_size, FLOATVAL));
+    VTABLE void init_int(INTVAL size) {
+        if (size < 0)
+            Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS,
+                _("FixedFloatArray: Cannot set array size to a negative number (%d)"), size);
+        SET_ATTR_size(INTERP, SELF, size);
+        SET_ATTR_float_array(INTERP, SELF, mem_gc_allocate_n_typed(INTERP, size, FLOATVAL));
         PObj_custom_destroy_SET(SELF);
     }
 

Modified: trunk/src/pmc/fixedintegerarray.pmc
==============================================================================
--- trunk/src/pmc/fixedintegerarray.pmc	Thu Mar 11 14:24:43 2010	(r44876)
+++ trunk/src/pmc/fixedintegerarray.pmc	Thu Mar 11 14:38:10 2010	(r44877)
@@ -54,6 +54,9 @@
 */
 
     VTABLE void init_int(INTVAL size) {
+        if (size < 0)
+            Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS,
+                _("FixedIntegerArray: Cannot set array size to a negative number (%d)"), size);
         SET_ATTR_size(INTERP, SELF, size);
         SET_ATTR_int_array(INTERP, SELF, mem_gc_allocate_n_typed(INTERP, size, INTVAL));
         PObj_custom_destroy_SET(SELF);

Modified: trunk/src/pmc/fixedpmcarray.pmc
==============================================================================
--- trunk/src/pmc/fixedpmcarray.pmc	Thu Mar 11 14:24:43 2010	(r44876)
+++ trunk/src/pmc/fixedpmcarray.pmc	Thu Mar 11 14:38:10 2010	(r44877)
@@ -92,7 +92,7 @@
 
         if (size < 0)
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
-                    _("FixedPMCArray: Cannot set array size to a negative number"));
+                    _("FixedPMCArray: Cannot set array size to a negative number (%d)"),size);
 
         SET_ATTR_size(INTERP, SELF, size);
         data           = mem_gc_allocate_n_typed(INTERP, size, PMC *);

Modified: trunk/src/pmc/fixedstringarray.pmc
==============================================================================
--- trunk/src/pmc/fixedstringarray.pmc	Thu Mar 11 14:24:43 2010	(r44876)
+++ trunk/src/pmc/fixedstringarray.pmc	Thu Mar 11 14:38:10 2010	(r44877)
@@ -56,7 +56,7 @@
     VTABLE void init_int(INTVAL size) {
         if (size < 0)
             Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS,
-                "Cannot instantiate PMC with negative size %d", size);
+                _("FixedStringArray: Cannot set array size to a negative number (%d)"), size);
         SET_ATTR_size(INTERP, SELF, size);
         SET_ATTR_str_array(INTERP, SELF, mem_gc_allocate_n_zeroed_typed(INTERP, size, STRING *));
         PObj_custom_mark_destroy_SETALL(SELF);

Modified: trunk/t/pmc/fixedbooleanarray.t
==============================================================================
--- trunk/t/pmc/fixedbooleanarray.t	Thu Mar 11 14:24:43 2010	(r44876)
+++ trunk/t/pmc/fixedbooleanarray.t	Thu Mar 11 14:38:10 2010	(r44877)
@@ -20,7 +20,7 @@
 .sub 'test' :main
     .include 'test_more.pir'
 
-    plan(39)
+    plan(41)
 
     setting_array_size()
     resizing_not_allowed()
@@ -38,6 +38,7 @@
     get_iter()
     fill()
     test_new_style_init()
+    test_invalid_init_tt1509()
 .end
 
 .sub 'setting_array_size'
@@ -343,6 +344,20 @@
     is($I0, 10, "New style init creates the correct # of elements for a key constant")
 .end
 
+.sub test_invalid_init_tt1509
+    throws_substring(<<'CODE', 'FixedBooleanArray: Cannot set array size to a negative number (-10)', 'New style init does not dump core for negative array lengths')
+    .sub main
+        $P0 = new ['FixedBooleanArray'], -10
+    .end
+CODE
+
+    throws_substring(<<'CODE', 'FixedBooleanArray: Cannot set array size to a negative number (-10)', 'New style init (key constant) does not dump core for negative array lengths')
+    .sub main
+        $P0 = new 'FixedBooleanArray', -10
+    .end
+CODE
+.end
+
 # Local Variables:
 #   mode: pir
 #   fill-column: 100

Modified: trunk/t/pmc/fixedfloatarray.t
==============================================================================
--- trunk/t/pmc/fixedfloatarray.t	Thu Mar 11 14:24:43 2010	(r44876)
+++ trunk/t/pmc/fixedfloatarray.t	Thu Mar 11 14:38:10 2010	(r44877)
@@ -20,7 +20,7 @@
 .sub main :main
     .include 'fp_equality.pasm'
     .include 'test_more.pir'
-    plan(28)
+    plan(30)
 
     array_size_tests()
     element_set_tests()
@@ -31,6 +31,7 @@
     interface_check()
     get_iter_test()
     test_new_style_init()
+    test_invalid_init_tt1509()
 .end
 
 .sub array_size_tests
@@ -258,6 +259,20 @@
     is($I0, 10, "New style init creates the correct # of elements for a key constant")
 .end
 
+.sub test_invalid_init_tt1509
+    throws_substring(<<'CODE', 'FixedFloatArray: Cannot set array size to a negative number (-10)', 'New style init does not dump core for negative array lengths')
+    .sub main
+        $P0 = new ['FixedFloatArray'], -10
+    .end
+CODE
+
+    throws_substring(<<'CODE', 'FixedFloatArray: Cannot set array size to a negative number (-10)', 'New style init (key constant) does not dump core for negative array lengths')
+    .sub main
+        $P0 = new 'FixedFloatArray', -10
+    .end
+CODE
+.end
+
 # Local Variables:
 #   mode: pir
 #   fill-column: 100

Modified: trunk/t/pmc/fixedintegerarray.t
==============================================================================
--- trunk/t/pmc/fixedintegerarray.t	Thu Mar 11 14:24:43 2010	(r44876)
+++ trunk/t/pmc/fixedintegerarray.t	Thu Mar 11 14:38:10 2010	(r44877)
@@ -19,7 +19,7 @@
 
 .sub 'main' :main
     .include 'test_more.pir'
-    plan(31)
+    plan(33)
 
     test_set_size()
     test_reset_size()
@@ -32,6 +32,7 @@
     test_get_iter()
     test_equality()
     test_new_style_init()
+    test_invalid_init_tt1509()
 .end
 
 .sub 'test_new_style_init'
@@ -255,6 +256,20 @@
     is($I0, 10, "New style init creates the correct # of elements")
 .end
 
+.sub test_invalid_init_tt1509
+    throws_substring(<<'CODE', 'FixedIntegerArray: Cannot set array size to a negative number (-10)', 'New style init does not dump core for negative array lengths')
+    .sub main
+        $P0 = new ['FixedIntegerArray'], -10
+    .end
+CODE
+
+    throws_substring(<<'CODE', 'FixedIntegerArray: Cannot set array size to a negative number (-10)', 'New style init (key constant) does not dump core for negative array lengths')
+    .sub main
+        $P0 = new 'FixedIntegerArray', -10
+    .end
+CODE
+.end
+
 # Local Variables:
 #   mode: pir
 #   fill-column: 100

Modified: trunk/t/pmc/fixedpmcarray.t
==============================================================================
--- trunk/t/pmc/fixedpmcarray.t	Thu Mar 11 14:24:43 2010	(r44876)
+++ trunk/t/pmc/fixedpmcarray.t	Thu Mar 11 14:38:10 2010	(r44877)
@@ -19,7 +19,7 @@
 
 .sub main :main
     .include 'test_more.pir'
-    plan(80)
+    plan(82)
     test_setting_array_size()
     test_assign_from_another()
     test_assign_self()
@@ -47,6 +47,7 @@
     test_sort()
     test_exists()
     test_new_style_init()
+    test_invalid_init_tt1509()
 .end
 
 .sub test_exists
@@ -679,6 +680,20 @@
     is($I0, 10, "New style init creates the correct # of elements for a key constant")
 .end
 
+.sub test_invalid_init_tt1509
+    throws_substring(<<'CODE', 'Cannot set array size to a negative number (-10)', 'New style init does not dump core for negative array lengths')
+    .sub main
+        $P0 = new ['FixedPMCArray'], -10
+    .end
+CODE
+
+    throws_substring(<<'CODE', 'Cannot set array size to a negative number (-10)', 'New style init (key constant) does not dump core for negative array lengths')
+    .sub main
+        $P0 = new 'FixedPMCArray', -10
+    .end
+CODE
+.end
+
 # Local Variables:
 #   mode: pir
 #   fill-column: 100

Modified: trunk/t/pmc/fixedstringarray.t
==============================================================================
--- trunk/t/pmc/fixedstringarray.t	Thu Mar 11 14:24:43 2010	(r44876)
+++ trunk/t/pmc/fixedstringarray.t	Thu Mar 11 14:38:10 2010	(r44877)
@@ -19,7 +19,7 @@
 
 .sub 'main' :main
     .include 'test_more.pir'
-    plan(48)
+    plan(50)
 
     test_set_size()
     test_reset_size()
@@ -39,6 +39,7 @@
     test_gc()
     test_number()
     test_new_style_init()
+    test_invalid_init_tt1509()
 .end
 
 .sub 'test_set_size'
@@ -389,6 +390,20 @@
     is($I0, 10, "New style init creates the correct # of elements for a key constant")
 .end
 
+.sub test_invalid_init_tt1509
+    throws_substring(<<'CODE', 'FixedStringArray: Cannot set array size to a negative number (-10)', 'New style init does not dump core for negative array lengths')
+    .sub main
+        $P0 = new ['FixedStringArray'], -10
+    .end
+CODE
+
+    throws_substring(<<'CODE', 'FixedStringArray: Cannot set array size to a negative number (-10)', 'New style init (key constant) does not dump core for negative array lengths')
+    .sub main
+        $P0 = new 'FixedStringArray', -10
+    .end
+CODE
+.end
+
 # Local Variables:
 #   mode: pir
 #   fill-column: 100


More information about the parrot-commits mailing list