Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit da8e6a2

Browse files
committed
(Merge 3.4) Closes #21780: make the unicodedata module "ssize_t clean" for
parsing parameters
2 parents 7f08406 + 65a3144 commit da8e6a2

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

Modules/unicodedata.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
1414
------------------------------------------------------------------------ */
1515

16+
#define PY_SSIZE_T_CLEAN
17+
1618
#include "Python.h"
1719
#include "ucnhash.h"
1820
#include "structmember.h"
@@ -1271,12 +1273,16 @@ unicodedata_lookup(PyObject* self, PyObject* args)
12711273
Py_UCS4 code;
12721274

12731275
char* name;
1274-
int namelen;
1276+
Py_ssize_t namelen;
12751277
unsigned int index;
12761278
if (!PyArg_ParseTuple(args, "s#:lookup", &name, &namelen))
12771279
return NULL;
1280+
if (namelen > INT_MAX) {
1281+
PyErr_SetString(PyExc_KeyError, "name too long");
1282+
return NULL;
1283+
}
12781284

1279-
if (!_getcode(self, name, namelen, &code, 1)) {
1285+
if (!_getcode(self, name, (int)namelen, &code, 1)) {
12801286
PyErr_Format(PyExc_KeyError, "undefined character name '%s'", name);
12811287
return NULL;
12821288
}

0 commit comments

Comments
 (0)