in reply to Really Odd Bug With LWP and Device::SerialPort

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);