Skip Menu |
Report information
Id: 67912
Status: resolved
Priority: 0/
Queue: perl5

Owner: Nobody
Requestors: dave.taylor.cpan [at] googlemail.com
Cc:
AdminCc:

Operating System: (no value)
PatchStatus: Applied
Severity: low
Type: unknown
Perl Version: (no value)
Fixed In: (no value)



Subject: syswrite prints garbage if called with empty scalar and non-zero offset
Date: Mon, 27 Jul 2009 10:01:00 +0200
To: perlbug [...] perl.org
From: David Taylor <dave.taylor.cpan [...] googlemail.com>
Download (untitled) / with headers
text/plain 473b
In a stock 5.10.0 perl with the default build options, syswrite prints garbage if called with the empty string as the scalar and a non-zero offset: $ /usr/local/refperl/5.10.0/bin/perl -e 'my $foo = ""; syswrite STDOUT, $foo, 100, 1' | less <DC>8 /null^@^@^@^Y^@^@^@^A^@^@^@ ^@^@^@^P^@^@^@X^V9 ^@^@^@^@<89>^@^@^@<80><A6>^U^H^@^@^@^@^@<A6>^U^H^@^@^@^@<80><A7>^U^H^@^@^@^@^@ <A7>^U^H^@^@^@^@<80><A8>^U^H^@^@^@^@^@<A9>^U^H^@^@^@^@^@<A5>^U^H^@^@^@^@<80><A4>^U^H^@ (END)
Download perlversion.txt
text/plain 2.1k

Message body is not shown because sender requested not to inline it.

CC: David Taylor (via RT) <perlbug-followup [...] perl.org>, bugs-bitbucket [...] netlabs.develooper.com
Subject: Re: [perl #67912] syswrite prints garbage if called with empty scalar and non-zero offset
Date: Mon, 27 Jul 2009 04:02:45 -0700
To: perl5-porters [...] perl.org
From: chromatic <chromatic [...] wgz.org>
Download (untitled) / with headers
text/plain 1.5k
On Monday 27 July 2009 01:01:32 David Taylor wrote: Show quoted text
> # New Ticket Created by David Taylor > # Please include the string: [perl #67912] > # in the subject line of all future correspondence about this issue. > # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=67912 > > > > In a stock 5.10.0 perl with the default build options, syswrite prints > garbage if called with the empty string as the scalar and a non-zero > offset: > > $ /usr/local/refperl/5.10.0/bin/perl -e 'my $foo = ""; syswrite > STDOUT, $foo, 100, 1' | less > <DC>8 /null^@^@^@^Y^@^@^@^A^@^@^@ ^@^@^@^P^@^@^@X^V9 >
^@^@^@^@<89>^@^@^@<80><A6>^U^H^@^@^@^@^@<A6>^U^H^@^@^@^@<80><A7>^U^H^@^@^@^ Show quoted text
>@^@ >
<A7>^U^H^@^@^@^@<80><A8>^U^H^@^@^@^@^@<A9>^U^H^@^@^@^@^@<A5>^U^H^@^@^@^@<80 Show quoted text
>><A4>^U^H^@ (END)
Confirmed in blead. This looks like a fencepost error. With the included patch, I get instead an error: $ ./perl -e 'my $foo = ""; syswrite STDOUT, $foo, 100, 1' Offset outside string at -e line 1. I suspect that the comparison should be > instead of >=, but it's late here and another set of eyes would help. diff --git a/pp_sys.c b/pp_sys.c index 23f79ba..ec12cd4 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -1919,7 +1919,7 @@ PP(pp_send) DIE(aTHX_ "Offset outside string"); } offset += blen_chars; - } else if (offset >= (IV)blen_chars && blen_chars > 0) { + } else if (offset >= (IV)blen_chars) { Safefree(tmpbuf); DIE(aTHX_ "Offset outside string"); } -- c
Subject: Re: [perl #67912] syswrite prints garbage if called with empty scalar and non-zero offset
Date: Mon, 27 Jul 2009 15:35:02 +0300
To: Perl 5 Porters <perl5-porters [...] perl.org>
From: Offer Kaye <offer.kaye [...] gmail.com>
Download (untitled) / with headers
text/plain 408b
On Mon, Jul 27, 2009 at 2:02 PM, chromatic wrote: Show quoted text
> > Confirmed in blead.  This looks like a fencepost error.  With the included > patch, I get instead an error: >
Maybe we should add a test for this, perhaps in t/op/sysio.t? I thought something like the attached patch (not tested). Unrelated question - looking at t/op/sysio.t I don't understand, why doesn't it use Test::More? Cheers, -- Offer Kaye

Message body is not shown because sender requested not to inline it.

Subject: Re: [perl #67912] syswrite prints garbage if called with empty scalar and non-zero offset
Date: Mon, 27 Jul 2009 15:07:08 +0200
To: chromatic <chromatic [...] wgz.org>, perlbug-followup [...] perl.org, bugs-bitbucket [...] netlabs.develooper.com
From: Vincent Pit <perl [...] profvince.com>
Show quoted text
> Confirmed in blead. This looks like a fencepost error. With the included > patch, I get instead an error: > > $ ./perl -e 'my $foo = ""; syswrite > STDOUT, $foo, 100, 1' > Offset outside string at -e line 1. > > I suspect that the comparison should be > instead of >=, but it's late here > and another set of eyes would help. > > diff --git a/pp_sys.c b/pp_sys.c > index 23f79ba..ec12cd4 100644 > --- a/pp_sys.c > +++ b/pp_sys.c > @@ -1919,7 +1919,7 @@ PP(pp_send) > DIE(aTHX_ "Offset outside string"); > } > offset += blen_chars; > - } else if (offset >= (IV)blen_chars && blen_chars > 0) { > + } else if (offset >= (IV)blen_chars) { > Safefree(tmpbuf); > DIE(aTHX_ "Offset outside string"); > } > > -- c >
I think that's the cause too, so I've applied it as 6100a0a495d0f5504fc134f242a1ebed97a87087 and I added a regression test with e41cc779424eaf419bea11fb7535e356b1113698. But I don't think >= should be replaced by >, because an offset of n is outside a string of length n. Vincent.
CC: bugs-bitbucket [...] netlabs.develooper.com
Subject: Re: [perl #67912] syswrite prints garbage if called with empty scalar and non-zero offset
Date: Mon, 27 Jul 2009 14:40:24 +0100
To: perlbug-followup [...] perl.org
From: Zefram <zefram [...] fysh.org>
Download (untitled) / with headers
text/plain 375b
Vincent Pit wrote: Show quoted text
>But I don't think >= should be replaced by >, because an offset of n is >outside a string of length n.
Offset of n is acceptable with a string of length n as long as you're not intending to read more than zero chars from it. The proper conditions for acceptability are: write_length >= 0 offset >= 0 offset + write_length <= string_length -zefram
CC: Perl 5 Porters <perl5-porters [...] perl.org>
Subject: Re: [perl #67912] syswrite prints garbage if called with empty scalar and non-zero offset
Date: Tue, 28 Jul 2009 17:02:29 +0100
To: Offer Kaye <offer.kaye [...] gmail.com>
From: Nicholas Clark <nick [...] ccl4.org>
Download (untitled) / with headers
text/plain 695b
On Mon, Jul 27, 2009 at 03:35:02PM +0300, Offer Kaye wrote: Show quoted text
> On Mon, Jul 27, 2009 at 2:02 PM, chromatic wrote:
> > > > Confirmed in blead.  This looks like a fencepost error.  With the included > > patch, I get instead an error: > >
> > Maybe we should add a test for this, perhaps in t/op/sysio.t? I > thought something like the attached patch (not tested). > > Unrelated question - looking at t/op/sysio.t I don't understand, why > doesn't it use Test::More?
There's a bootstrapping order on tests. The initial tests run avoid relying on complex constructions such as packages and OO, so that we get clear failure diagnostics if we introduce a bug that makes them fail. Nicholas Clark


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org