[svn:parrot] r37562 - in trunk: src/ops t/op
cotto at svn.parrot.org
cotto at svn.parrot.org
Wed Mar 18 21:38:34 UTC 2009
Author: cotto
Date: Wed Mar 18 21:38:32 2009
New Revision: 37562
URL: https://trac.parrot.org/parrot/changeset/37562
Log:
[string] make the repeat opcode more paranoid about negative numbers
fuzzing++
Modified:
trunk/src/ops/string.ops
trunk/t/op/string.t
Modified: trunk/src/ops/string.ops
==============================================================================
--- trunk/src/ops/string.ops Wed Mar 18 21:18:30 2009 (r37561)
+++ trunk/src/ops/string.ops Wed Mar 18 21:38:32 2009 (r37562)
@@ -145,10 +145,22 @@
}
inline op repeat(invar PMC, invar PMC, in INT) :base_core {
+ if ($3 < 0) {
+ opcode_t *handler = Parrot_ex_throw_from_op_args(interp, NULL,
+ EXCEPTION_NEG_REPEAT,
+ "Cannot repeat with negative arg");
+ goto ADDRESS(handler);
+ }
$1 = VTABLE_repeat_int(interp, $2, $3, $1);
}
inline op repeat(invar PMC, invar PMC, invar PMC) :base_core {
+ if (VTABLE_get_integer(interp, $3) < 0) {
+ opcode_t *handler = Parrot_ex_throw_from_op_args(interp, NULL,
+ EXCEPTION_NEG_REPEAT,
+ "Cannot repeat with negative arg");
+ goto ADDRESS(handler);
+ }
$1 = VTABLE_repeat(interp, $2, $3, $1);
}
Modified: trunk/t/op/string.t
==============================================================================
--- trunk/t/op/string.t Wed Mar 18 21:18:30 2009 (r37561)
+++ trunk/t/op/string.t Wed Mar 18 21:38:32 2009 (r37562)
@@ -7,7 +7,7 @@
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 160;
+use Parrot::Test tests => 162;
use Parrot::Config;
=head1 NAME
@@ -1279,6 +1279,27 @@
end
CODE
+pir_error_output_like( <<'CODE', qr/Cannot repeat with negative arg\n/, 'repeat OOB, repeat_p_p_p' );
+.sub main
+ $P0 = new ['String']
+ $P1 = new ['String']
+ $P2 = new ['Integer']
+
+ $P2 = -1
+
+ repeat $P1, $P0, $P2
+.end
+CODE
+
+pir_error_output_like( <<'CODE', qr/Cannot repeat with negative arg\n/, 'repeat OOB, repeate_p_p_i' );
+.sub main
+ $P0 = new ['String']
+ $P1 = new ['String']
+
+ repeat $P1, $P0, -1
+.end
+CODE
+
pasm_output_is( <<'CODE', <<'OUTPUT', 'index, 3-arg form' );
set S0, "Parrot"
set S1, "Par"
More information about the parrot-commits
mailing list