Change 34015 by [EMAIL PROTECTED] on 2008/06/07 16:16:05
Integrate:
[ 33955]
Integrate:
...
[ 33951]
Add index() tests for embedded nulls
Subject: Re: [perl #53746] bug with index() matching beyond end of
string when \0 bytes (00000000) are involved
From: Abigail <[EMAIL PROTECTED]>
Date: Tue, 6 May 2008 14:57:36 +0200
Message-Id: <[EMAIL PROTECTED]>
[ 33952]
[perl #53746] bug with index() matching beyond end of string
An off-by-one error meant that index($str,...)
was effectively being executed as index("$str\0", ...).
Probably introduced by change #26511.
Affected files ...
... //depot/maint-5.8/perl/t/op/index.t#8 integrate
... //depot/maint-5.8/perl/util.c#165 integrate
Differences ...
==== //depot/maint-5.8/perl/t/op/index.t#8 (xtext) ====
Index: perl/t/op/index.t
--- perl/t/op/index.t#7~30663~ 2007-03-21 11:17:59.000000000 -0700
+++ perl/t/op/index.t 2008-06-07 09:16:05.000000000 -0700
@@ -7,7 +7,7 @@
}
use strict;
-plan( tests => 69 );
+plan( tests => 111 );
my $foo = 'Now is the time for all good men to come to the aid of their
country.';
@@ -155,3 +155,41 @@
local ${^UTF8CACHE} = -1;
is(index($t, 'xyz'), 4, "0xfffffffd and utf8cache");
}
+
+
+# Tests for NUL characters.
+{
+ my @tests = (
+ ["", -1, -1, -1],
+ ["foo", -1, -1, -1],
+ ["\0", 0, -1, -1],
+ ["\0\0", 0, 0, -1],
+ ["\0\0\0", 0, 0, 0],
+ ["foo\0", 3, -1, -1],
+ ["foo\0foo\0\0", 3, 7, -1],
+ );
+ foreach my $l (1 .. 3) {
+ my $q = "\0" x $l;
+ my $i = 0;
+ foreach my $test (@tests) {
+ $i ++;
+ my $str = $$test [0];
+ my $res = $$test [$l];
+
+ {
+ is (index ($str, $q), $res, "Find NUL character(s)");
+ }
+
+ #
+ # Bug #53746 shows a difference between variables and literals,
+ # so test literals as well.
+ #
+ my $test_str = qq {is (index ("$str", "$q"), $res, } .
+ qq {"Find NUL character(s)")};
+ $test_str =~ s/\0/\\0/g;
+
+ eval $test_str;
+ die $@ if $@;
+ }
+ }
+}
==== //depot/maint-5.8/perl/util.c#165 (text) ====
Index: perl/util.c
--- perl/util.c#164~33813~ 2008-05-10 09:43:45.000000000 -0700
+++ perl/util.c 2008-06-07 09:16:05.000000000 -0700
@@ -434,9 +434,9 @@
little >= lend)
return (char*)big;
{
- char first = *little++;
+ char first = *little;
const char *s, *x;
- bigend -= lend - little;
+ bigend -= lend - little++;
OUTER:
while (big <= bigend) {
if (*big++ == first) {
End of Patch.