[Python-checkins] cpython (3.4): Closes #21780: make the unicodedata module "ssize_t clean" for parsing

victor.stinner python-checkins at python.org
Tue Jul 1 16:47:04 CEST 2014


http://hg.python.org/cpython/rev/b82ff2d7f5ef
changeset:   91507:b82ff2d7f5ef
branch:      3.4
parent:      91505:36e884e65e45
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Tue Jul 01 16:45:52 2014 +0200
summary:
  Closes #21780: make the unicodedata module "ssize_t clean" for parsing parameters

files:
  Modules/unicodedata.c |  10 ++++++++--
  1 files changed, 8 insertions(+), 2 deletions(-)


diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c
--- 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 @@
     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;
     }

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list