summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-07-01 16:45:52 +0200
committerVictor Stinner <victor.stinner@gmail.com>2014-07-01 16:45:52 +0200
commit0760e0d68043952ca28f05e3b6bf5c0ee71bc0d4 (patch)
tree72d39a42adb342b32c57db09af972a9575e3703e
parent1eb2ce163f2e694419297cac0f03fcbc221e5017 (diff)
downloadcpython-0760e0d68043952ca28f05e3b6bf5c0ee71bc0d4.tar.gz
Closes #21780: make the unicodedata module "ssize_t clean" for parsing parameters
-rw-r--r--Modules/unicodedata.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c
index 3253db21f1..3979f65738 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;
}