Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d9ef74e

Browse files
committed
Issue 24244: Prevents termination when an invalid format string is encountered on Windows.
1 parent 945fff4 commit d9ef74e

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ Core and Builtins
5858
Library
5959
-------
6060

61+
- Issue 24244: Prevents termination when an invalid format string is
62+
encountered on Windows in strftime.
63+
6164
- Issue #23973: PEP 484: Add the typing module.
6265

6366
- Issue #20035: Replaced the ``tkinter._fix`` module used for setting up the

Modules/timemodule.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -616,13 +616,6 @@ time_strftime(PyObject *self, PyObject *args)
616616
{
617617
if (outbuf[1]=='#')
618618
++outbuf; /* not documented by python, */
619-
if (outbuf[1]=='\0' ||
620-
!strchr("aAbBcdHIjmMpSUwWxXyYzZ%", outbuf[1]))
621-
{
622-
PyErr_SetString(PyExc_ValueError, "Invalid format string");
623-
Py_DECREF(format);
624-
return NULL;
625-
}
626619
if ((outbuf[1] == 'y') && buf.tm_year < 0)
627620
{
628621
PyErr_SetString(PyExc_ValueError,
@@ -660,7 +653,9 @@ time_strftime(PyObject *self, PyObject *args)
660653
PyErr_NoMemory();
661654
break;
662655
}
656+
_Py_BEGIN_SUPPRESS_IPH
663657
buflen = format_time(outbuf, i, fmt, &buf);
658+
_Py_END_SUPPRESS_IPH
664659
#if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__)
665660
err = errno;
666661
#endif

0 commit comments

Comments
 (0)