Here's the code to reproduce it. Easier to see on windows, since it produces a buffer overflow. On linux, you would have to hook up a serial analyzer to see that the bytes don't get written (or are garbled).
You have to put a valid serial in for $port (COM1, COM2, etc, on windows.../dev/ttyXXX on linux) to see the bug.
There's a line to uncomment that will "cure" the bug with what should be essentially a no-op.
Also, if you replace the $url with a non-https url, the bug doesn't show itself.
#!/usr/bin/perl
use strict;
use warnings;
#
# You must change what's below to a valid comm port, or the bug won't
# show itself
#
my $port="COM9";
my $url='https://github.com';
use LWP::UserAgent;
my $serial;
BEGIN {
if ($^O eq "MSWin32" or $^O eq "cygwin") {
eval "use Win32::SerialPort";
die "$@\n" if ($@);
} else {
eval "use Device::SerialPort";
die "$@\n" if ($@);
}
}
if ($^O eq "MSWin32" or $^O eq "cygwin") {
$serial = Win32::SerialPort->new($port,1);
} else {
$serial = Device::SerialPort->new($port,1);
}
my $useragent = LWP::UserAgent->new();
my $request = new HTTP::Request;
$request->method("GET");
$request->url($url);
my $response = $useragent->request($request);
my $data = $response->decoded_content;
#
# the line below grabs the first 6 bytes, which would be <!DOCT
# but, the bug is triggered
#
$data=~s/(......).*/$1/s;
#
# now, uncomment the line below, and the bug doesn't show itself
# $data=substr($data,0);
#
print "data is [$data]\n";
$serial->baudrate(9600);
$serial->parity('none');
$serial->databits(8);
$serial->stopbits(1);
$serial->handshake('none');
$serial->write_settings();
$serial->write($data);
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|