Kaydet (Commit) 3e5d87bb authored tarafından Benjamin Peterson's avatar Benjamin Peterson

disallow a negative idx parameter

üst f10cc46a
...@@ -1468,10 +1468,11 @@ scan_once_str(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_t *n ...@@ -1468,10 +1468,11 @@ scan_once_str(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_t *n
PyObject *res; PyObject *res;
char *str = PyString_AS_STRING(pystr); char *str = PyString_AS_STRING(pystr);
Py_ssize_t length = PyString_GET_SIZE(pystr); Py_ssize_t length = PyString_GET_SIZE(pystr);
if (idx < 0) if (idx < 0) {
/* Compatibility with the Python version. */ PyErr_SetString(PyExc_ValueError, "idx cannot be negative");
idx += length; return NULL;
if (idx < 0 || idx >= length) { }
if (idx >= length) {
PyErr_SetNone(PyExc_StopIteration); PyErr_SetNone(PyExc_StopIteration);
return NULL; return NULL;
} }
...@@ -1558,10 +1559,11 @@ scan_once_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_ ...@@ -1558,10 +1559,11 @@ scan_once_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_
PyObject *res; PyObject *res;
Py_UNICODE *str = PyUnicode_AS_UNICODE(pystr); Py_UNICODE *str = PyUnicode_AS_UNICODE(pystr);
Py_ssize_t length = PyUnicode_GET_SIZE(pystr); Py_ssize_t length = PyUnicode_GET_SIZE(pystr);
if (idx < 0) if (idx < 0) {
/* Compatibility with Python version. */ PyErr_SetString(PyExc_ValueError, "idx cannot be negative");
idx += length; return NULL;
if (idx < 0 || idx >= length) { }
if (idx >= length) {
PyErr_SetNone(PyExc_StopIteration); PyErr_SetNone(PyExc_StopIteration);
return NULL; return NULL;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment