[svn:parrot] r48533 - in branches/substr_eq_at: src/string t/op
chromatic at svn.parrot.org
chromatic at svn.parrot.org
Mon Aug 16 19:28:19 UTC 2010
Author: chromatic
Date: Mon Aug 16 19:28:18 2010
New Revision: 48533
URL: https://trac.parrot.org/parrot/changeset/48533
Log:
[str] Sanitized Parrot_str_compare_offset.
These new boundary checks help its safety, but they might not be sufficient.
Additional tests welcome.
Modified:
branches/substr_eq_at/src/string/api.c
branches/substr_eq_at/t/op/substr_cmp.t
Modified: branches/substr_eq_at/src/string/api.c
==============================================================================
--- branches/substr_eq_at/src/string/api.c Mon Aug 16 19:14:05 2010 (r48532)
+++ branches/substr_eq_at/src/string/api.c Mon Aug 16 19:28:18 2010 (r48533)
@@ -1350,6 +1350,12 @@
{
ASSERT_ARGS(Parrot_str_compare_offset)
+ if (offset > a->strlen)
+ return -1;
+
+ if (offset + length > a->strlen)
+ length = offset - a->strlen;
+
if (a->encoding == b->encoding)
return memcmp(a->strstart + offset, b->strstart, length);
Modified: branches/substr_eq_at/t/op/substr_cmp.t
==============================================================================
--- branches/substr_eq_at/t/op/substr_cmp.t Mon Aug 16 19:14:05 2010 (r48532)
+++ branches/substr_eq_at/t/op/substr_cmp.t Mon Aug 16 19:28:18 2010 (r48533)
@@ -19,7 +19,7 @@
.sub main :main
.include 'test_more.pir'
- plan(14)
+ plan(16)
test_cmp_str_at_i_s_sc_ic_ic()
.end
@@ -67,6 +67,15 @@
$I0 = cmp_str_at $S0, 'xy', 3, 3
is( $I0, -1, "2nd argument is short" )
+
+ $I0 = cmp_str_at $S0, '', 0, 0
+ is( $I0, 0, "2nd argument is empty" )
+
+ $I0 = cmp_str_at $S0, 'my def = Integer', 0, 16
+ is( $I0, -1, "2nd argument is longer" )
+
+ $I0 = cmp_str_at $S0, 'my def = Integer', 15, 1
+ is( $I0, -1, "offset out of bounds of first string" )
.end
# Local Variables:
More information about the parrot-commits
mailing list