Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[t][TT#1509] Prevent core dumps by preventing negative length array c…

…reation. Tests for FFA, FPA, FIA, FSA and FBA

git-svn-id: https://svn.parrot.org/parrot/trunk@44877 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
commit 4d64842dccb498770df398b602eb42c4b284e9e2 1 parent 60a92f2
@leto leto authored
View
4 src/pmc/fixedbooleanarray.pmc
@@ -73,6 +73,10 @@ Initializes the array.
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,
View
9 src/pmc/fixedfloatarray.pmc
@@ -56,9 +56,12 @@ Initializes the array.
*/
- 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);
}
View
3  src/pmc/fixedintegerarray.pmc
@@ -54,6 +54,9 @@ Initializes the array.
*/
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);
View
2  src/pmc/fixedpmcarray.pmc
@@ -92,7 +92,7 @@ Initializes the array.
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 *);
View
2  src/pmc/fixedstringarray.pmc
@@ -56,7 +56,7 @@ Initializes the array.
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);
View
17 t/pmc/fixedbooleanarray.t
@@ -20,7 +20,7 @@ out-of-bounds test. Checks INT and PMC keys.
.sub 'test' :main
.include 'test_more.pir'
- plan(39)
+ plan(41)
setting_array_size()
resizing_not_allowed()
@@ -38,6 +38,7 @@ out-of-bounds test. Checks INT and PMC keys.
get_iter()
fill()
test_new_style_init()
+ test_invalid_init_tt1509()
.end
.sub 'setting_array_size'
@@ -343,6 +344,20 @@ out-of-bounds test. Checks INT and PMC keys.
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
View
17 t/pmc/fixedfloatarray.t
@@ -20,7 +20,7 @@ out-of-bounds test. Checks INT and PMC keys.
.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 @@ out-of-bounds test. Checks INT and PMC keys.
interface_check()
get_iter_test()
test_new_style_init()
+ test_invalid_init_tt1509()
.end
.sub array_size_tests
@@ -258,6 +259,20 @@ loop:
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
View
17 t/pmc/fixedintegerarray.t
@@ -19,7 +19,7 @@ out-of-bounds test. Checks INT and PMC keys.
.sub 'main' :main
.include 'test_more.pir'
- plan(31)
+ plan(33)
test_set_size()
test_reset_size()
@@ -32,6 +32,7 @@ out-of-bounds test. Checks INT and PMC keys.
test_get_iter()
test_equality()
test_new_style_init()
+ test_invalid_init_tt1509()
.end
.sub 'test_new_style_init'
@@ -255,6 +256,20 @@ out-of-bounds test. Checks INT and PMC keys.
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
View
17 t/pmc/fixedpmcarray.t
@@ -19,7 +19,7 @@ out-of-bounds test. Checks INT and PMC keys.
.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 @@ out-of-bounds test. Checks INT and PMC keys.
test_sort()
test_exists()
test_new_style_init()
+ test_invalid_init_tt1509()
.end
.sub test_exists
@@ -679,6 +680,20 @@ CODE
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
View
17 t/pmc/fixedstringarray.t
@@ -19,7 +19,7 @@ out-of-bounds test. Checks INT and PMC keys.
.sub 'main' :main
.include 'test_more.pir'
- plan(48)
+ plan(50)
test_set_size()
test_reset_size()
@@ -39,6 +39,7 @@ out-of-bounds test. Checks INT and PMC keys.
test_gc()
test_number()
test_new_style_init()
+ test_invalid_init_tt1509()
.end
.sub 'test_set_size'
@@ -389,6 +390,20 @@ out-of-bounds test. Checks INT and PMC keys.
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
Please sign in to comment.
Something went wrong with that request. Please try again.