Skip to content

Instantly share code, notes, and snippets.

/upgraded.diff Secret

Created January 27, 2017 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5c104445b17feca80645d2162d21599e to your computer and use it in GitHub Desktop.
Save anonymous/5c104445b17feca80645d2162d21599e to your computer and use it in GitHub Desktop.
diff --git a/lib/Mojo/IOLoop/Stream.pm b/lib/Mojo/IOLoop/Stream.pm
index 92cb0aef7..cbf594fda 100644
--- a/lib/Mojo/IOLoop/Stream.pm
+++ b/lib/Mojo/IOLoop/Stream.pm
@@ -77,6 +77,8 @@ sub timeout {
sub write {
my ($self, $chunk, $cb) = @_;
+ # IO::Socket::SSL may corrupt upgraded strings
+ utf8::downgrade $chunk;
$self->{buffer} .= $chunk;
if ($cb) { $self->once(drain => $cb) }
elsif (!length $self->{buffer}) { return $self }
diff --git a/t/mojo/ioloop_tls.t b/t/mojo/ioloop_tls.t
index 288fb28c3..6a2355d9f 100644
--- a/t/mojo/ioloop_tls.t
+++ b/t/mojo/ioloop_tls.t
@@ -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 });
}
@@ -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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment