summaryrefslogtreecommitdiff
path: root/Modules/datetimemodule.c
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2006-03-20 01:58:39 +0000
committerNeal Norwitz <nnorwitz@gmail.com>2006-03-20 01:58:39 +0000
commitb06a2b617f672e134540ad86847187931532077b (patch)
treea64dc067ffc84dd8a82166b50a6f047f26b4d83c /Modules/datetimemodule.c
parentca192a1a614dfdcdb4246ad14c378c798b5c3711 (diff)
downloadcpython-b06a2b617f672e134540ad86847187931532077b.tar.gz
Fix problem spotted by Coverity that occurs if tzinfo.tzname().replace()
returns a non-string when converting %Z. Will backport.
Diffstat (limited to 'Modules/datetimemodule.c')
-rw-r--r--Modules/datetimemodule.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index 199ee654f8..6823110185 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -1228,8 +1228,8 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
}
}
assert(zreplacement != NULL);
- ptoappend = PyString_AsString(zreplacement);
- ntoappend = PyString_Size(zreplacement);
+ ptoappend = PyString_AS_STRING(zreplacement);
+ ntoappend = PyString_GET_SIZE(zreplacement);
}
else if (ch == 'Z') {
/* format tzname */
@@ -1257,14 +1257,18 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
Py_DECREF(temp);
if (Zreplacement == NULL)
goto Done;
+ if (!PyString_Check(Zreplacement)) {
+ PyErr_SetString(PyExc_TypeError, "tzname.replace() did not return a string");
+ goto Done;
+ }
}
else
Py_DECREF(temp);
}
}
assert(Zreplacement != NULL);
- ptoappend = PyString_AsString(Zreplacement);
- ntoappend = PyString_Size(Zreplacement);
+ ptoappend = PyString_AS_STRING(Zreplacement);
+ ntoappend = PyString_GET_SIZE(Zreplacement);
}
else {
/* percent followed by neither z nor Z */
@@ -1275,6 +1279,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
/* Append the ntoappend chars starting at ptoappend to
* the new format.
*/
+ assert(ptoappend != NULL);
assert(ntoappend >= 0);
if (ntoappend == 0)
continue;