Commit 7af6eec6 authored by Benjamin Peterson's avatar Benjamin Peterson

Merged revisions 65147 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r65147 | bob.ippolito | 2008-07-19 16:59:50 -0500 (Sat, 19 Jul 2008) | 1 line

  #3322: bounds checking for _json.scanstring
........
parent 1aea30aa
...@@ -236,6 +236,10 @@ scanstring_str(PyObject *pystr, Py_ssize_t end, char *encoding, int strict) ...@@ -236,6 +236,10 @@ scanstring_str(PyObject *pystr, Py_ssize_t end, char *encoding, int strict)
if (chunks == NULL) { if (chunks == NULL) {
goto bail; goto bail;
} }
if (end < 0 || len <= end) {
PyErr_SetString(PyExc_ValueError, "end is out of bounds");
goto bail;
}
while (1) { while (1) {
/* Find the end of the string or the next escape */ /* Find the end of the string or the next escape */
Py_UNICODE c = 0; Py_UNICODE c = 0;
...@@ -246,7 +250,7 @@ scanstring_str(PyObject *pystr, Py_ssize_t end, char *encoding, int strict) ...@@ -246,7 +250,7 @@ scanstring_str(PyObject *pystr, Py_ssize_t end, char *encoding, int strict)
break; break;
} }
else if (strict && c <= 0x1f) { else if (strict && c <= 0x1f) {
raise_errmsg("Invalid control character at", pystr, begin); raise_errmsg("Invalid control character at", pystr, next);
goto bail; goto bail;
} }
} }
...@@ -401,6 +405,10 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict) ...@@ -401,6 +405,10 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict)
if (chunks == NULL) { if (chunks == NULL) {
goto bail; goto bail;
} }
if (end < 0 || len <= end) {
PyErr_SetString(PyExc_ValueError, "end is out of bounds");
goto bail;
}
while (1) { while (1) {
/* Find the end of the string or the next escape */ /* Find the end of the string or the next escape */
Py_UNICODE c = 0; Py_UNICODE c = 0;
...@@ -411,7 +419,7 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict) ...@@ -411,7 +419,7 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict)
break; break;
} }
else if (strict && c <= 0x1f) { else if (strict && c <= 0x1f) {
raise_errmsg("Invalid control character at", pystr, begin); raise_errmsg("Invalid control character at", pystr, next);
goto bail; goto bail;
} }
} }
......
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