summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2007-06-11 02:16:10 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2007-06-11 02:16:10 (GMT)
commit5c9a81a3d828e775a1500bb8d84dc1dab59513ad (patch)
tree868a2214eae0f4ac5f30719a835a63d730fcfff8 /Objects
parentba965deea89299611454e43be005df357b75b11d (diff)
downloadcpython-5c9a81a3d828e775a1500bb8d84dc1dab59513ad.zip
cpython-5c9a81a3d828e775a1500bb8d84dc1dab59513ad.tar.gz
cpython-5c9a81a3d828e775a1500bb8d84dc1dab59513ad.tar.bz2
Fix a bug when there was a newline in the string expandtabs was called on.
This also catches another condition that can overflow. Will backport.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/stringobject.c10
-rw-r--r--Objects/unicodeobject.c10
2 files changed, 16 insertions, 4 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index d7ad5cc..3870343 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -3322,7 +3322,8 @@ string_expandtabs(PyStringObject *self, PyObject *args)
if (tabsize > 0) {
j += tabsize - (j % tabsize);
if (old_j > j) {
- PyErr_SetString(PyExc_OverflowError, "new string is too long");
+ PyErr_SetString(PyExc_OverflowError,
+ "new string is too long");
return NULL;
}
old_j = j;
@@ -3332,7 +3333,12 @@ string_expandtabs(PyStringObject *self, PyObject *args)
j++;
if (*p == '\n' || *p == '\r') {
i += j;
- j = 0;
+ old_j = j = 0;
+ if (i < 0) {
+ PyErr_SetString(PyExc_OverflowError,
+ "new string is too long");
+ return NULL;
+ }
}
}
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 3481d19..ad33b8e 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -5705,7 +5705,8 @@ unicode_expandtabs(PyUnicodeObject *self, PyObject *args)
if (tabsize > 0) {
j += tabsize - (j % tabsize);
if (old_j > j) {
- PyErr_SetString(PyExc_OverflowError, "new string is too long");
+ PyErr_SetString(PyExc_OverflowError,
+ "new string is too long");
return NULL;
}
old_j = j;
@@ -5715,7 +5716,12 @@ unicode_expandtabs(PyUnicodeObject *self, PyObject *args)
j++;
if (*p == '\n' || *p == '\r') {
i += j;
- j = 0;
+ old_j = j = 0;
+ if (i < 0) {
+ PyErr_SetString(PyExc_OverflowError,
+ "new string is too long");
+ return NULL;
+ }
}
}