]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
disallow a negative idx parameter
authorBenjamin Peterson <benjamin@python.org>
Mon, 14 Apr 2014 15:45:21 +0000 (11:45 -0400)
committerBenjamin Peterson <benjamin@python.org>
Mon, 14 Apr 2014 15:45:21 +0000 (11:45 -0400)
Modules/_json.c

index e54b0b94bc5001222ce85387d54c39a5e4305261..b1c3108cbc0ae56233b3e3c43c0ca6cbc7ed6fcb 100644 (file)
@@ -902,10 +902,11 @@ scan_once_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_
     PyObject *res;
     Py_UNICODE *str = PyUnicode_AS_UNICODE(pystr);
     Py_ssize_t length = PyUnicode_GET_SIZE(pystr);
-    if (idx < 0)
-        /* Compatibility with Python version. */
-        idx += length;
-    if (idx < 0 || idx >= length) {
+    if (idx < 0) {
+        PyErr_SetString(PyExc_ValueError, "idx canont be negative");
+        return NULL;
+    }
+    if (idx >= length) {
         PyErr_SetNone(PyExc_StopIteration);
         return NULL;
     }