diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-07-01 14:46:12 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-07-01 14:46:12 (GMT) |
commit | da8e6a2dff7ed9487189701789c586ebc323d36d (patch) | |
tree | c819749aec5d22025b27f764358798b5fb909195 /Modules | |
parent | 7f084064e8f0ca815af4c436cd2cb9f131024bb9 (diff) | |
parent | 65a3144e541462821233402561b91e4d6bfe7799 (diff) | |
download | cpython-da8e6a2dff7ed9487189701789c586ebc323d36d.zip cpython-da8e6a2dff7ed9487189701789c586ebc323d36d.tar.gz cpython-da8e6a2dff7ed9487189701789c586ebc323d36d.tar.bz2 |
(Merge 3.4) Closes #21780: make the unicodedata module "ssize_t clean" for
parsing parameters
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/unicodedata.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c index 3253db2..3979f65 100644 --- a/Modules/unicodedata.c +++ b/Modules/unicodedata.c @@ -13,6 +13,8 @@ ------------------------------------------------------------------------ */ +#define PY_SSIZE_T_CLEAN + #include "Python.h" #include "ucnhash.h" #include "structmember.h" @@ -1271,12 +1273,16 @@ unicodedata_lookup(PyObject* self, PyObject* args) Py_UCS4 code; char* name; - int namelen; + Py_ssize_t namelen; unsigned int index; if (!PyArg_ParseTuple(args, "s#:lookup", &name, &namelen)) return NULL; + if (namelen > INT_MAX) { + PyErr_SetString(PyExc_KeyError, "name too long"); + return NULL; + } - if (!_getcode(self, name, namelen, &code, 1)) { + if (!_getcode(self, name, (int)namelen, &code, 1)) { PyErr_Format(PyExc_KeyError, "undefined character name '%s'", name); return NULL; } |