From ab9f15865f0bdb3a056da035e63d3297f7c6f3c8 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Sat, 27 Nov 2010 05:40:53 -0800 Subject: [PATCH] [perl #78716] Bogus read after seek beyond end of string This is a signedness problem that ffe0bb5ab did not take into account. (STRLEN)-10 > 0 returns true for me. --- ext/PerlIO-scalar/scalar.xs | 3 ++- ext/PerlIO-scalar/t/scalar.t | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ext/PerlIO-scalar/scalar.xs b/ext/PerlIO-scalar/scalar.xs index b93b9e9..6fe551d 100644 --- a/ext/PerlIO-scalar/scalar.xs +++ b/ext/PerlIO-scalar/scalar.xs @@ -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) diff --git a/ext/PerlIO-scalar/t/scalar.t b/ext/PerlIO-scalar/t/scalar.t index adc5b8e..1aee4b0 100644 --- a/ext/PerlIO-scalar/t/scalar.t +++ b/ext/PerlIO-scalar/t/scalar.t @@ -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"; @@ -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'; +} -- 2.7.4