Created
August 30, 2010 09:25
-
-
Save jbergstroem/557217 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/_pylibmcmodule.c b/_pylibmcmodule.c | |
index 6c8fd5e..e5eaab8 100644 | |
--- a/_pylibmcmodule.c | |
+++ b/_pylibmcmodule.c | |
@@ -1715,7 +1715,7 @@ static PyObject *_PylibMC_GetPickles(const char *attname) { | |
static PyObject *_PylibMC_Unpickle(const char *buff, size_t size) { | |
PyObject *pickle_load; | |
PyObject *retval = NULL; | |
- | |
+ | |
retval = NULL; | |
pickle_load = _PylibMC_GetPickles("loads"); | |
if (pickle_load != NULL) { | |
@@ -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) { | |
diff --git a/tests.py b/tests.py | |
index 018e5dc..890ba99 100644 | |
--- a/tests.py | |
+++ b/tests.py | |
@@ -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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment