Permalink
Browse files

When receiving bad magic in the binary protocol, hang up.

try_read_command's return value of 0 indicates to the caller that more
data is needed, thus it changes the connection state to conn_waiting
which blows away the closing state and the connection stays open
forever accumulating bad input.
  • Loading branch information...
1 parent a155b04 commit 0a1e88dafc02db59d64366b85441d73a7ddb87a9 @dustin dustin committed with Trond Norbye May 13, 2009
Showing with 17 additions and 1 deletion.
  1. +1 −1 memcached.c
  2. +16 −0 t/issue_50.t
View
@@ -2841,7 +2841,7 @@ static int try_read_command(conn *c) {
c->binary_header.request.magic);
}
conn_set_state(c, conn_closing);
- return 0;
+ return -1;
}
c->msgcurr = 0;
View
@@ -0,0 +1,16 @@
+#!/usr/bin/perl
+
+use strict;
+use Test::More tests => 1;
+use FindBin qw($Bin);
+use lib "$Bin/lib";
+use MemcachedTest;
+
+my $server = new_memcached('-B binary');
+my $sock = $server->sock;
+
+$SIG{ALRM} = sub { die "alarm\n" };
+alarm(2);
+print $sock "Here's a bunch of garbage that doesn't look like the bin prot.";
+my $rv = <$sock>;
+ok(1, "Either the above worked and quit, or hung forever.");

0 comments on commit 0a1e88d

Please sign in to comment.