summaryrefslogtreecommitdiffstats
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-10-08 19:45:38 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-10-08 19:45:38 (GMT)
commit9c0e1f83af433a9eebb70cd41adcff2b0d608e05 (patch)
treee3919bc1e9d43077b3a6460948479a9366693562 /Objects/unicodeobject.c
parent48b1c3fcfc47b720a721ef887dd495ad667f567f (diff)
downloadcpython-9c0e1f83af433a9eebb70cd41adcff2b0d608e05.zip
cpython-9c0e1f83af433a9eebb70cd41adcff2b0d608e05.tar.gz
cpython-9c0e1f83af433a9eebb70cd41adcff2b0d608e05.tar.bz2
Issue #28379: Added sanity checks and tests for PyUnicode_CopyCharacters().
Patch by Xiang Zhang.
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 176ec13..b734eec 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -1366,15 +1366,19 @@ PyUnicode_CopyCharacters(PyObject *to, Py_ssize_t to_start,
if (PyUnicode_READY(to) == -1)
return -1;
- if (from_start < 0) {
+ if ((size_t)from_start > (size_t)PyUnicode_GET_LENGTH(from)) {
PyErr_SetString(PyExc_IndexError, "string index out of range");
return -1;
}
- if (to_start < 0) {
+ if ((size_t)to_start > (size_t)PyUnicode_GET_LENGTH(to)) {
PyErr_SetString(PyExc_IndexError, "string index out of range");
return -1;
}
- how_many = Py_MIN(PyUnicode_GET_LENGTH(from), how_many);
+ if (how_many < 0) {
+ PyErr_SetString(PyExc_SystemError, "how_many cannot be negative");
+ return -1;
+ }
+ how_many = Py_MIN(PyUnicode_GET_LENGTH(from)-from_start, how_many);
if (to_start + how_many > PyUnicode_GET_LENGTH(to)) {
PyErr_Format(PyExc_SystemError,
"Cannot write %zi characters at %zi "