[Python-checkins] r70114 - python/branches/py3k/Modules/timemodule.c
amaury.forgeotdarc
python-checkins at python.org
Tue Mar 3 00:52:57 CET 2009
Author: amaury.forgeotdarc
Date: Tue Mar 3 00:52:57 2009
New Revision: 70114
Log:
re-merge r69268 (issue4804) from trunk:
Now that the C runtime assertions are not silenced any more,
we must provide checks for the format string of strftime
Modified:
python/branches/py3k/Modules/timemodule.c
Modified: python/branches/py3k/Modules/timemodule.c
==============================================================================
--- python/branches/py3k/Modules/timemodule.c (original)
+++ python/branches/py3k/Modules/timemodule.c Tue Mar 3 00:52:57 2009
@@ -513,6 +513,24 @@
if (format == NULL)
return NULL;
fmt = PyBytes_AS_STRING(format);
+
+#ifdef MS_WINDOWS
+ /* check that the format string contains only valid directives */
+ for(outbuf = strchr(fmt, '%');
+ outbuf != NULL;
+ outbuf = strchr(outbuf+2, '%'))
+ {
+ if (outbuf[1]=='#')
+ ++outbuf; /* not documented by python, */
+ if (outbuf[1]=='\0' ||
+ !strchr("aAbBcdfHIjmMpSUwWxXyYzZ%", outbuf[1]))
+ {
+ PyErr_SetString(PyExc_ValueError, "Invalid format string");
+ return 0;
+ }
+ }
+#endif
+
fmtlen = strlen(fmt);
/* I hate these functions that presume you know how big the output
More information about the Python-checkins
mailing list