Fix off-by-one in key length check

Fixes #18
This commit is contained in:
Johan Bergström 2010-08-30 13:41:34 +02:00 committed by lericson
parent 314562c437
commit 725134931b
2 changed files with 11 additions and 3 deletions

View File

@ -1754,9 +1754,10 @@ static int _PylibMC_CheckKey(PyObject *key) {
}
static int _PylibMC_CheckKeyStringAndSize(char *key, Py_ssize_t size) {
if (size > MEMCACHED_MAX_KEY) {
/* libmemcached pads max_key_size with one byte for null termination */
if (size >= MEMCACHED_MAX_KEY) {
PyErr_Format(PyExc_ValueError, "key too long, max is %d",
MEMCACHED_MAX_KEY);
MEMCACHED_MAX_KEY - 1);
return 0;
#ifdef NO_EMPTY_KEYS /* I wish... */
} else if (size == 0) {

View File

@ -256,6 +256,13 @@ Ormod's Zero-byte Adventure Story
True
>>> bc.get_multi(["\0\0"])
{'\x00\x00': 'ORMOD'}
Test server/client max length
>>> mc.get('x'*250)
>>> mc.get('x'*251)
Traceback (most recent call last):
...
ValueError: key too long, max is 250
"""
# Used to test pickling.