Skip to content

Commit 9186959

Browse files
committed
MB-12763: large body length value causes moxi to restart
Disconnect the client if it tries to send a packet bigger than 20MB, or a packet where the extlen/keylen is bigger than the entire packet. Change-Id: I60a5ac0e7e289009fee1f0dff9ff9aedf9bbe19d Reviewed-on: http://review.couchbase.org/52829 Tested-by: buildbot <[email protected]> Reviewed-by: Dave Rigby <[email protected]>
1 parent be8bc9c commit 9186959

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/memcached.c

+25
Original file line numberDiff line numberDiff line change
@@ -3178,6 +3178,31 @@ int try_read_command(conn *c) {
31783178
return -1;
31793179
}
31803180

3181+
/*
3182+
* disconnect the client if it tries to send illegal packets
3183+
* or packets that's too big. The max limit is 20Mb, so
3184+
* disconnect the client if it sends > 21.
3185+
*/
3186+
if (c->binary_header.request.bodylen > (21 * 1024 * 1024)) {
3187+
if (settings.verbose) {
3188+
moxi_log_write("Packet too big: 0x%x\n",
3189+
c->binary_header.request.bodylen);
3190+
}
3191+
conn_set_state(c, conn_closing);
3192+
return -1;
3193+
}
3194+
3195+
uint32_t body = c->binary_header.request.keylen;
3196+
body += c->binary_header.request.extlen;
3197+
if (body > c->binary_header.request.bodylen) {
3198+
if (settings.verbose) {
3199+
moxi_log_write("Content of packet bigger than encoded body: 0x%x > 0x%x\n",
3200+
body, c->binary_header.request.bodylen);
3201+
}
3202+
conn_set_state(c, conn_closing);
3203+
return -1;
3204+
}
3205+
31813206
c->msgcurr = 0;
31823207
c->msgused = 0;
31833208
c->iovused = 0;

0 commit comments

Comments
 (0)