Skip to content

Commit

Permalink
[perl #78716] Bogus read after seek beyond end of string
Browse files Browse the repository at this point in the history
This is a signedness problem that ffe0bb5 did not take into account.
(STRLEN)-10 > 0 returns true for me.
  • Loading branch information
Father Chrysostomos committed Nov 27, 2010
1 parent 6a8c869 commit ab9f158
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ext/PerlIO-scalar/scalar.xs
Expand Up @@ -150,7 +150,8 @@ PerlIOScalar_read(pTHX_ PerlIO *f, void *vbuf, Size_t count)
PerlIOScalar *s = PerlIOSelf(f, PerlIOScalar);
SV *sv = s->var;
char *p;
STRLEN len, got;
STRLEN len;
I32 got;
p = SvPV(sv, len);
got = len - (STRLEN)(s->posn);
if (got <= 0)
Expand Down
11 changes: 9 additions & 2 deletions ext/PerlIO-scalar/t/scalar.t
Expand Up @@ -16,7 +16,7 @@ use Fcntl qw(SEEK_SET SEEK_CUR SEEK_END); # Not 0, 1, 2 everywhere.

$| = 1;

use Test::More tests => 69;
use Test::More tests => 70;

my $fh;
my $var = "aaa\n";
Expand Down Expand Up @@ -276,4 +276,11 @@ EOF
is($s, ':F:S(GHI):O:F:R:F:R:F:R', 'tied actions - read');
}


# [perl #78716] Seeking beyond the end of the string, then reading
{
my $str = '1234567890';
open my $strIn, '<', \$str;
seek $strIn, 15, 1;
is read($strIn, my $buffer, 5), 0,
'seek beyond end end of string followed by read';
}

0 comments on commit ab9f158

Please sign in to comment.