Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
work around a problem with IO::Socket::SSL
  • Loading branch information
kraih committed Jan 27, 2017
1 parent a1c045a commit 42a873e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
5 changes: 4 additions & 1 deletion Changes
@@ -1,5 +1,8 @@

7.23 2017-01-26
7.23 2017-01-27
- Fixed a data corruption problem in Mojo::IOLoop::Stream, caused by a
dependency of IO::Socket::SSL on the internal representation of strings,
which differs from IO::Socket::IP.

7.22 2017-01-25
- Added ports method to Mojo::Server::Daemon.
Expand Down
2 changes: 2 additions & 0 deletions lib/Mojo/IOLoop/Stream.pm
Expand Up @@ -77,6 +77,8 @@ sub timeout {
sub write {
my ($self, $chunk, $cb) = @_;

# IO::Socket::SSL will corrupt data with the wrong internal representation
utf8::downgrade $chunk;
$self->{buffer} .= $chunk;
if ($cb) { $self->once(drain => $cb) }
elsif (!length $self->{buffer}) { return $self }
Expand Down
11 changes: 7 additions & 4 deletions t/mojo/ioloop_tls.t
Expand Up @@ -30,15 +30,18 @@ plan skip_all => 'IO::Socket::SSL 1.94+ required for this test!'
# openssl req -x509 -days 7300 -key bad.key -in bad.csr -out bad.crt
use Mojo::IOLoop;

# Built-in certificate
# Built-in certificate (and upgraded string)
my $loop = Mojo::IOLoop->new;
my $delay = $loop->delay;
my $upgraded
= "\x01\x00\x00\x00\x00\x00\xD0\x00\x0A\x00\x0B\x00\x00\x00\x84\x0B";
utf8::upgrade $upgraded;
my ($server, $client);
my $end = $delay->begin;
my $id = $loop->server(
{address => '127.0.0.1', tls => 1} => sub {
my ($loop, $stream) = @_;
$stream->write('test' => sub { shift->write('321') });
$stream->write($upgraded => sub { shift->write('321') });
$stream->on(close => $end);
$stream->on(read => sub { $server .= pop });
}
Expand All @@ -55,8 +58,8 @@ $loop->client(
}
);
$delay->wait;
is $server, 'tset123', 'right content';
is $client, 'test321', 'right content';
is $server, 'tset123', 'right content';
is $client, "${upgraded}321", 'right content';

# Valid client certificate
$delay = Mojo::IOLoop->delay;
Expand Down

0 comments on commit 42a873e

Please sign in to comment.