Permalink
Browse files

Gracefully detect cut-off netstrings.

  • Loading branch information...
supernovus committed Sep 26, 2011
1 parent 547e6ec commit 72c64e43dd0261d8b920ab8f66b9d346746af839
Showing with 7 additions and 2 deletions.
  1. +2 −1 .gitignore
  2. +5 −1 lib/SCGI.pm
View
@@ -1,2 +1,3 @@
Makefile
-blib
+blib
+*.swp
View
@@ -26,14 +26,18 @@ class SCGI::Request {
}
method parse {
- $.request = $.connection.get();#recv();
+ $.request = $.connection.get();#recv(); ## FIXME!
+ my $rlen = $.request.chars;
if $.debug { $*ERR.say: "Receieved request: $.request"; }
if $.request ~~ / ^ (\d+) \: / {
if $.debug {
$*ERR.say: "A proper request was received, parsing into an ENV";
}
my $length = +$0;
my $offset = $0.Str.chars + 1;
+ if ($rlen < $length + $offset) {
+ return self.err("malformed netstring, length is incorrect.");
+ }
my $env_string = $.request.substr($offset, $length);
my $comma = $.request.substr($offset+$length, 1);
if $comma ne ',' {

0 comments on commit 72c64e4

Please sign in to comment.