Skip to content

Commit 3705435

Browse files
dustinTrond Norbye
authored and
Trond Norbye
committed
Enforce some hard limits on SASL mechanism length.
1 parent dd11bde commit 3705435

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

memcached.c

+6
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,12 @@ static void process_bin_sasl_auth(conn *c) {
15261526
int nkey = c->binary_header.request.keylen;
15271527
int vlen = c->binary_header.request.bodylen - nkey;
15281528

1529+
if (nkey > MAX_SASL_MECH_LEN) {
1530+
write_bin_error(c, PROTOCOL_BINARY_RESPONSE_EINVAL, vlen);
1531+
c->write_and_go = conn_swallow;
1532+
return;
1533+
}
1534+
15291535
char *key = binary_get_key(c);
15301536
assert(key);
15311537

sasl_defs.h

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#ifndef SASL_DEFS_H
22
#define SASL_DEFS_H 1
33

4+
// Longest one I could find was ``9798-U-RSA-SHA1-ENC''
5+
#define MAX_SASL_MECH_LEN 32
6+
47
#if defined(HAVE_SASL_SASL_H) && defined(ENABLE_SASL)
58

69
#include <sasl/sasl.h>

t/binary-sasl.t

+7-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ my $supports_sasl = supports_sasl();
1212
use Test::More;
1313

1414
if (supports_sasl()) {
15-
plan tests => 19;
15+
plan tests => 20;
1616
} else {
1717
plan tests => 1;
1818
eval {
@@ -161,6 +161,9 @@ system("echo testpass | saslpasswd2 -a memcached -c -p testuser");
161161

162162
$mc = MC::Client->new;
163163

164+
# Attempt a bad auth mech.
165+
is ($mc->authenticate('testuser', 'testpass', "X" x 40), 0x4, "bad mech");
166+
164167
# Attempt bad authentication.
165168
is ($mc->authenticate('testuser', 'wrongpassword'), 0x20, "bad auth");
166169

@@ -221,9 +224,10 @@ sub new {
221224
}
222225

223226
sub authenticate {
224-
my ($self, $user, $pass)= @_;
227+
my ($self, $user, $pass, $mech)= @_;
228+
$mech ||= 'PLAIN';
225229
my $buf = sprintf("%c%s%c%s", 0, $user, 0, $pass);
226-
my ($status, $rv, undef) = $self->_do_command(::CMD_SASL_AUTH, "PLAIN", $buf, '');
230+
my ($status, $rv, undef) = $self->_do_command(::CMD_SASL_AUTH, $mech, $buf, '');
227231
return $status;
228232
}
229233
sub list_mechs {

0 commit comments

Comments
 (0)