[Python-checkins] cpython (3.3): Issue13674 Correct crash with strftime %y format under Windows
tim.golden
python-checkins at python.org
Tue Nov 12 13:58:19 CET 2013
http://hg.python.org/cpython/rev/1537f14cc690
changeset: 87060:1537f14cc690
branch: 3.3
parent: 87058:5198e8f325f5
user: Tim Golden <mail at timgolden.me.uk>
date: Tue Nov 12 12:36:54 2013 +0000
summary:
Issue13674 Correct crash with strftime %y format under Windows
files:
Lib/test/test_strftime.py | 26 +++++++++++++++++++++++++-
Modules/timemodule.c | 7 +++++++
2 files changed, 32 insertions(+), 1 deletions(-)
diff --git a/Lib/test/test_strftime.py b/Lib/test/test_strftime.py
--- a/Lib/test/test_strftime.py
+++ b/Lib/test/test_strftime.py
@@ -176,8 +176,32 @@
(e[0], e[2]))
print(" Expected %s, but got %s" % (e[1], result))
+
+class Y1900Tests(unittest.TestCase):
+ """A limitation of the MS C runtime library is that it crashes if
+ a date before 1900 is passed with a format string containing "%y"
+ """
+
+ @unittest.skipUnless(sys.platform == "win32", "Only applies to Windows")
+ def test_y_before_1900_win(self):
+ with self.assertRaises(ValueError):
+ time.strftime("%y", (1899, 1, 1, 0, 0, 0, 0, 0, 0))
+
+ @unittest.skipIf(sys.platform == "win32", "Doesn't apply on Windows")
+ def test_y_before_1900_nonwin(self):
+ self.assertEquals(
+ time.strftime("%y", (1899, 1, 1, 0, 0, 0, 0, 0, 0)), "99")
+
+ def test_y_1900(self):
+ self.assertEquals(
+ time.strftime("%y", (1900, 1, 1, 0, 0, 0, 0, 0, 0)), "00")
+
+ def test_y_after_1900(self):
+ self.assertEquals(
+ time.strftime("%y", (2013, 1, 1, 0, 0, 0, 0, 0, 0)), "13")
+
def test_main():
- support.run_unittest(StrftimeTest)
+ support.run_unittest(StrftimeTest, Y1900Tests)
if __name__ == '__main__':
test_main()
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -632,6 +632,13 @@
Py_DECREF(format);
return NULL;
}
+ if ((outbuf[1] == 'y') && buf.tm_year < 0)
+ {
+ PyErr_SetString(PyExc_ValueError,
+ "format %y requires year >= 1900 on Windows");
+ Py_DECREF(format);
+ return NULL;
+ }
}
#endif
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list