mirror of
https://github.com/python/cpython.git
synced 2025-07-30 22:54:16 +00:00
Issue #10653: Fix time.strftime() on Windows, check for invalid format strings
This commit is contained in:
parent
de49d64dbc
commit
5a3ff79fd6
1 changed files with 4 additions and 4 deletions
|
@ -463,16 +463,16 @@ time_strftime(PyObject *self, PyObject *args)
|
||||||
fmt = PyBytes_AS_STRING(format);
|
fmt = PyBytes_AS_STRING(format);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MS_WINDOWS) && defined(HAVE_WCSFTIME)
|
#if defined(MS_WINDOWS)
|
||||||
/* check that the format string contains only valid directives */
|
/* check that the format string contains only valid directives */
|
||||||
for(outbuf = wcschr(fmt, L'%');
|
for(outbuf = strchr(fmt, '%');
|
||||||
outbuf != NULL;
|
outbuf != NULL;
|
||||||
outbuf = wcschr(outbuf+2, L'%'))
|
outbuf = strchr(outbuf+2, '%'))
|
||||||
{
|
{
|
||||||
if (outbuf[1]=='#')
|
if (outbuf[1]=='#')
|
||||||
++outbuf; /* not documented by python, */
|
++outbuf; /* not documented by python, */
|
||||||
if (outbuf[1]=='\0' ||
|
if (outbuf[1]=='\0' ||
|
||||||
!wcschr(L"aAbBcdHIjmMpSUwWxXyYzZ%", outbuf[1]))
|
!strchr("aAbBcdHIjmMpSUwWxXyYzZ%", outbuf[1]))
|
||||||
{
|
{
|
||||||
PyErr_SetString(PyExc_ValueError, "Invalid format string");
|
PyErr_SetString(PyExc_ValueError, "Invalid format string");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue