Skip Menu |
 

This queue is for tickets about the POE-Component-SpreadClient CPAN distribution.

Report information
The Basics
Id: 65795
Status: resolved
Priority: 0/
Queue: POE-Component-SpreadClient

People
Owner: Nobody in particular
Requestors: rdb [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Spread message unpacking leaves trailing NULs
Download (untitled) / with headers
text/plain 865b
The Spread client, when receiving admin messages, unpacks the binary message as follows: ( $gid1, $gid2, $gid3, $num_memb, $member ) = unpack( "IIIIa*", $message ); however, when delivered as parameters to _sp_admin, this equates out to $data->{WHO} having values like: '#sli1409#count6^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@' The fix is to replace 'a' with 'Z' in unpack: ( $gid1, $gid2, $gid3, $num_memb, $member ) = unpack( "IIIIZ*", $message ); Then $data->{WHO} comes back as a "normal" string (e.g. "#sli1409#count6"), representing its true value and allowing simple processing of things like: if ($data->{WHO} eq $priv_name) { ... } the above test will *always* fail, since it can never be 'eq' without the trailing NULs.. I've been having to use a regex match to allow for them, forcing: if ($data->{WHO} =~ /^$priv_name/) { ... } Fix attached.
Subject: member_parsing.diff
Download member_parsing.diff
text/x-diff 461b
--- SpreadClient.pm~ 2011-02-16 13:26:27.000000000 -0800 +++ SpreadClient.pm 2011-02-16 13:26:40.000000000 -0800 @@ -509,7 +509,7 @@ # Parse the message! my ( $gid1, $gid2, $gid3, $num_memb, $member ); eval { - ( $gid1, $gid2, $gid3, $num_memb, $member ) = unpack( "IIIIa*", $message ); + ( $gid1, $gid2, $gid3, $num_memb, $member ) = unpack( "IIIIZ*", $message ); }; if ( $@ ) { # Inform our registered listeners
Subject: Re: [rt.cpan.org #65795] Spread message unpacking leaves trailing NULs
Date: Wed, 16 Feb 2011 17:12:41 -0700
To: bug-POE-Component-SpreadClient [...] rt.cpan.org
From: "perl [...] 0ne.us" <perl [...] 0ne.us>
Rob Bloodgood via RT wrote: Show quoted text
> Wed Feb 16 16:33:41 2011: Request 65795 was acted upon. > Transaction: Ticket created by RDB > Queue: POE-Component-SpreadClient > Subject: Spread message unpacking leaves trailing NULs > Broken in: (no value) > Severity: Wishlist > Owner: Nobody > Requestors: rdb@cpan.org > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=65795 > > > > The Spread client, when receiving admin messages, unpacks the binary > message as follows: > > ( $gid1, $gid2, $gid3, $num_memb, $member ) = unpack( "IIIIa*", > $message ); > > however, when delivered as parameters to _sp_admin, this equates out > to $data->{WHO} having values like: > > '#sli1409#count6^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@' > > The fix is to replace 'a' with 'Z' in unpack: > > ( $gid1, $gid2, $gid3, $num_memb, $member ) = unpack( "IIIIZ*", > $message ); > > Then $data->{WHO} comes back as a "normal" string > (e.g. "#sli1409#count6"), representing its true value and allowing > simple processing of things like: > > if ($data->{WHO} eq $priv_name) { ... } > > the above test will *always* fail, since it can never be 'eq' without > the trailing NULs.. I've been having to use a regex match to allow for > them, forcing: > > if ($data->{WHO} =~ /^$priv_name/) { ... } > > Fix attached. >
Thanks for this! I've tracked down the source of the pack string and it's from Spread::Message. Look at 0.21 on CPAN and line 1092. The bug is my fault, as I didn't copy the next 2 lines, ha! They are: ($gid[0],$gid[1],$gid[2],$numg,$who) = unpack("IIIIa*",$msg); $who =~ s/[[:cntrl:]]+/ /go; # Just to clean it up $who =~ s/\s+$/ /go; # No space at end thanks As I'm not exactly a pack guru do you prefer to use Z or a with the extra clean-up? I've tried looking through the Spread C sources to see if it's possible to send a NUL as part of the message to no luck. However, I suspect it's safe to use Z - I wanted your confirmation before I push a new version to the unsuspecting masses on CPAN :)
Subject: Re: [rt.cpan.org #65795] Spread message unpacking leaves trailing NULs
Date: Wed, 16 Feb 2011 16:21:02 -0800
To: bug-POE-Component-SpreadClient [...] rt.cpan.org
From: Rob Bloodgood <rob [...] exitexchange.com>
Download (untitled) / with headers
text/plain 2.7k
well based on the output: the message body is a "fixed size", the NULs are just padding. So, since in C-space the first NUL is enough to terminate parsing but perl is "smarter", we're actually over-supporting it, IMO. Especially since the last field is absolutely a simple string. no need for the extra NULs. I suspect the other author wasn't quite as sure why there was "binary garbage" on the end of his message... and [:ctrl:] matches ^@, e.g. NUL. So yes, we want 'Z' unpacking. :) On Wed, Feb 16, 2011 at 4:12 PM, Apocalypse via RT < bug-POE-Component-SpreadClient@rt.cpan.org> wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=65795 > > > Rob Bloodgood via RT wrote:
> > Wed Feb 16 16:33:41 2011: Request 65795 was acted upon. > > Transaction: Ticket created by RDB > > Queue: POE-Component-SpreadClient > > Subject: Spread message unpacking leaves trailing NULs > > Broken in: (no value) > > Severity: Wishlist > > Owner: Nobody > > Requestors: rdb@cpan.org > > Status: new > > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=65795 > > > > > > > The Spread client, when receiving admin messages, unpacks the binary > > message as follows: > > > > ( $gid1, $gid2, $gid3, $num_memb, $member ) = unpack( "IIIIa*", > > $message ); > > > > however, when delivered as parameters to _sp_admin, this equates out > > to $data->{WHO} having values like: > > > > '#sli1409#count6^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@' > > > > The fix is to replace 'a' with 'Z' in unpack: > > > > ( $gid1, $gid2, $gid3, $num_memb, $member ) = unpack( "IIIIZ*", > > $message ); > > > > Then $data->{WHO} comes back as a "normal" string > > (e.g. "#sli1409#count6"), representing its true value and allowing > > simple processing of things like: > > > > if ($data->{WHO} eq $priv_name) { ... } > > > > the above test will *always* fail, since it can never be 'eq' without > > the trailing NULs.. I've been having to use a regex match to allow for > > them, forcing: > > > > if ($data->{WHO} =~ /^$priv_name/) { ... } > > > > Fix attached. > >
> Thanks for this! I've tracked down the source of the pack string and > it's from Spread::Message. Look at 0.21 on CPAN and line 1092. > > The bug is my fault, as I didn't copy the next 2 lines, ha! They are: > > ($gid[0],$gid[1],$gid[2],$numg,$who) = unpack("IIIIa*",$msg); > > $who =~ s/[[:cntrl:]]+/ /go; # Just to clean it up > $who =~ s/\s+$/ /go; # No space at end thanks > > As I'm not exactly a pack guru do you prefer to use Z or a with the > extra clean-up? I've tried looking through the Spread C sources to see > if it's possible to send a NUL as part of the message to no luck. > However, I suspect it's safe to use Z - I wanted your confirmation > before I push a new version to the unsuspecting masses on CPAN :) > >
Download (untitled) / with headers
text/plain 118b
As always, I greatly appreciate your help with this module! v1.002 was just uploaded to CPAN, thanks! -- ~Apocalypse


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

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.