[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2017-09-05 Thread STINNER Victor

STINNER Victor added the comment:

This issue should be fixed by my commit 
eeadf5fc231163ec97a8010754d9c995c7c14876.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2016-06-30 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Thank you Eryk.

Sad, a simple solution doesn't help. We have returned to the old decision -- 
won't fix.

--
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2016-06-26 Thread Mark Lawrence

Changes by Mark Lawrence :


--
nosy:  -BreamoreBoy

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2016-06-26 Thread Eryk Sun

Eryk Sun added the comment:

To resolve the crash on Windows in 2.7 requires backporting checktm(). Using 
asctime_s doesn't solve the problem. The CRT still calls the default invalid 
parameter handler, which kills the process -- as shown by the following ctypes 
example:

from ctypes import *
libc = CDLL('msvcr90')

class tm(Structure):
_fields_ = (('tm_sec', c_int),
('tm_min', c_int),
('tm_hour', c_int),
('tm_mday', c_int),
('tm_mon', c_int),
('tm_year', c_int),
('tm_wday', c_int),
('tm_yday', c_int),
('tm_isdst', c_int))

libc._localtime32.restype = POINTER(tm)
libc.asctime_s.restype = c_char_p

t = c_int()
libc._time32(byref(t))
lt = libc._localtime32(byref(t))
sbuf = (c_char * 100)()

>>> libc.asctime_s(sbuf, sizeof(sbuf), lt)
>>> sbuf.value
'Sun Jun 26 19:22:47 2016\n'

>>> lt[0].tm_hour = -1
>>> libc.asctime_s(sbuf, sizeof(sbuf), lt)

Breakpoint 0 hit
MSVCR90!_invoke_watson:
`6b8950e4 4053pushrbx
0:000> k5
Child-SP  RetAddr   Call Site
`005ef628 `6b8952d4 MSVCR90!_invoke_watson
`005ef630 `6b859830 MSVCR90!_invalid_parameter+0x70
`005ef670 `1d1aff53 MSVCR90!asctime_s+0x2fc
`005ef6b0 `1d1ae7fc _ctypes!ffi_call_AMD64+0x77
`005ef700 `1d1aa4c6 _ctypes!ffi_call+0x8c

--
nosy: +eryksun

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2016-06-26 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Benjamin, there is a crash, and there is a simple patch that presumably fixes a 
crash. I think fixing crashes has high priority. The patch is tested on Linux 
and needs to be tested on Windows.

--
components: +Windows
nosy: +paul.moore, steve.dower, tim.golden, zach.ware
status: closed -> open

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2013-02-05 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

 'Mon Jan  1 -01:00:00 2011\n'

This is obviously wrong because trailing '\n' was not dropped.

The issue is not about what is more wrong. The issue is about Python crash. At 
least we should add a warning in the documentation that incorrect data may 
crash Python on some platforms.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16137
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2013-02-05 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

A new patch uses asctime_s() on Windows (this crash was observed only on 
Windows). This should prevent a crash. In additional it drops '\n' from a 
result even if the result is longer than usually (this happened on Linux when 
an invalid time is used).

Please run test_time on Windows.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16137
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2013-02-05 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


Added file: http://bugs.python.org/file28958/asctime_s.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16137
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2013-02-05 Thread STINNER Victor

STINNER Victor added the comment:

asctime_s.patch: you should catch ValueError on each call to
self.assertNotIn(). You can use PyString_FromStringAndSize() instead
of writing the NUL character, it may be safer (to not modify the
output of asctime).

2013/2/5 Serhiy Storchaka rep...@bugs.python.org:

 Changes by Serhiy Storchaka storch...@gmail.com:


 Added file: http://bugs.python.org/file28958/asctime_s.patch

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue16137
 ___

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16137
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2013-02-05 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Thank you for comments, Victor. Here is an updated patch.

--
Added file: http://bugs.python.org/file28963/asctime_s_2.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16137
___diff -r 20f0c5398e97 Lib/test/test_time.py
--- a/Lib/test/test_time.py Mon Feb 04 10:29:38 2013 -0500
+++ b/Lib/test/test_time.py Tue Feb 05 16:04:32 2013 +0200
@@ -128,10 +128,15 @@
 # self.assertRaises(ValueError, time.asctime,
 #  (12345, 1, 0, 0, 0, 0, 0, 0, 0))
 # XXX: For now, just make sure we don't have a crash:
-try:
-time.asctime((12345, 1, 1, 0, 0, 0, 0, 1, 0))
-except ValueError:
-pass
+def check(tm):
+try:
+self.assertNotIn('\n', time.asctime(tm))
+except ValueError:
+pass
+check((12345, 1, 1, 0, 0, 0, 0, 1, 0))
+# Issue #16137
+check((2013, 2, 5, -1, 0, 0, 0, 0, 0))
+check((2013, 2, 5, 101, 0, 0, 0, 0, 0))
 
 @unittest.skipIf(not hasattr(time, tzset),
 time module has no attribute tzset)
diff -r 20f0c5398e97 Misc/NEWS
--- a/Misc/NEWS Mon Feb 04 10:29:38 2013 -0500
+++ b/Misc/NEWS Tue Feb 05 16:04:32 2013 +0200
@@ -199,6 +199,10 @@
 Library
 ---
 
+- Issue #16137: Fix a segmentation fault when time.asctime() called with an
+  illegal time (i.e. with a negative hour) on Windows.  On other platforms a
+  result of such call no more contains a trailing '\n'.
+
 - Issue #6083: Fix multiple segmentation faults occured when PyArg_ParseTuple
   parses nested mutating sequence.
 
diff -r 20f0c5398e97 Modules/timemodule.c
--- a/Modules/timemodule.c  Mon Feb 04 10:29:38 2013 -0500
+++ b/Modules/timemodule.c  Tue Feb 05 16:04:32 2013 +0200
@@ -563,7 +563,10 @@
 {
 PyObject *tup = NULL;
 struct tm buf;
-char *p;
+char *p, *q;
+#ifdef MS_WINDOWS
+char sbuf[100];
+#endif
 if (!PyArg_UnpackTuple(args, asctime, 0, 1, tup))
 return NULL;
 if (tup == NULL) {
@@ -571,14 +574,24 @@
 buf = *localtime(tt);
 } else if (!gettmarg(tup, buf))
 return NULL;
+#ifdef MS_WINDOWS
+if (asctime_s(sbuf, sizeof(sbuf) - 1, buf) != 0)
+p = NULL;
+else {
+p = sbuf;
+sbuf[sizeof(sbuf) - 1] = '\0';
+}
+#else
 p = asctime(buf);
+#endif
 if (p == NULL) {
 PyErr_SetString(PyExc_ValueError, invalid time);
 return NULL;
 }
-if (p[24] == '\n')
-p[24] = '\0';
-return PyString_FromString(p);
+q = strchr(p, '\n');
+if (q == NULL)
+q = strchr(p, '\0'); /* end of string */
+return PyString_FromStringAndSize(p, q - p);
 }
 
 PyDoc_STRVAR(asctime_doc,
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2013-02-04 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

Benjamin,

I am assigning this to you because 2.7.4 release is probably the last chance to 
do something about this behavior in 2.7 series.

I am tentatively resolving this as won't fix.  In 3.x, we decided that well 
defined behavior is more important than bug compatibility on broken platforms.  
For 2.x, however, the priorities are different.  In this particular case, it is 
very easy to work around platform bug, but if we add a bound check, we may 
break code that works.

For example, on a recent Mac OS X release and preloaded Python 2.7, I get:

Python 2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type help, copyright, credits or license for more information.
 import time
 time.asctime((2011,1,1,-1,0,0,0,0,0))
'Mon Jan  1 -01:00:00 2011\n'

This behavior is not obviously wrong.

Please close this or make it a release blocker.  I don't think there is any 
value in letting this linger past 2.7.4 release.

--
assignee:  - benjamin.peterson
nosy: +benjamin.peterson
resolution:  - wont fix
status: open - pending

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16137
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2013-02-04 Thread Benjamin Peterson

Benjamin Peterson added the comment:

This is long behavior standing, which we can leave in 2.x.

--
status: pending - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16137
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2013-01-27 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Any news?

--
priority: normal - critical

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16137
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2012-11-18 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Here is a patch which includes backported issue6608 and issue8013.  This should 
fix this crash.

--
keywords: +patch
stage: needs patch - patch review
Added file: http://bugs.python.org/file28034/asctime.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16137
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2012-11-18 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

I recall a discussion in which it was argued that look before you leap-style 
argument checking that we implemented in py3k was a feature and backporting it 
to 2.x could potentially break code running on platforms with promiscuous (and 
possibly buggy) asctime().

I am +0 on back-porting, but would like someone else to make the call.

--
nosy: +haypo, lemburg

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16137
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2012-11-12 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Alexander, do you want to backport r87736 to 2.7?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16137
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2012-10-19 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Alexander, looks as you changes in r87736 was not backported to 2.7.

--
components: +Extension Modules -Library (Lib)
nosy: +belopolsky
stage:  - needs patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16137
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2012-10-05 Thread Mark Lawrence

Mark Lawrence added the comment:

I can reproduce this on Windows Vista running 2.7.3.  With 3.3.0 I get
 faulty_time = time.asctime(initial_struct_time)
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: Tuple or struct_time argument required


--
nosy: +BreamoreBoy

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16137
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2012-10-05 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Viktor, what happen when a large positive number (=100) used as tm_hour?

--
nosy: +serhiy.storchaka

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16137
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2012-10-05 Thread Viktor Chynarov

Viktor Chynarov added the comment:

Serhiy, when I use a large number, Python also crashes.

 initial_struct_time = [tm for tm in time.localtime()]
 initial_struct_time[3] = 101
 faulty_time = time.asctime(initial_struct_time)

The above code leads to crash.

My Python version information and computer architecture are shown below:
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on 
win32

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16137
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2012-10-05 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Yes, it looks as issue8013. Fix was not applied to 2.7.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16137
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2012-10-05 Thread R. David Murray

R. David Murray added the comment:

This sounds like Issue 10814, but that was supposedly fixed.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16137
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2012-10-05 Thread R. David Murray

R. David Murray added the comment:

Ah, looks like Serhiy found the correct issue.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16137
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2012-10-05 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

No, it's you found (msg172016) the correct issue. ;)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16137
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2012-10-04 Thread Viktor Chynarov

New submission from Viktor Chynarov:

If a that has a negative tm_hour is passed as an argument to time.asctime(), 
Python crashes. 

 initial_struct_time = [tm for tm in time.localtime()]
 initial_struct_time[3] = -1
 faulty_time = time.asctime(initial_struct_time)

--
components: Library (Lib)
messages: 172005
nosy: Viktor.Chynarov
priority: normal
severity: normal
status: open
title: Using time.asctime() with an array with negative tm_hour causes Python 
Crash.
type: crash
versions: Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16137
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2012-10-04 Thread Viktor Chynarov

Viktor Chynarov added the comment:

If an array created from a struct_time that has a negative tm_hour is passed as 
an argument to time.asctime(), Python crashes. 

 initial_struct_time = [tm for tm in time.localtime()]
 initial_struct_time[3] = -1
 faulty_time = time.asctime(initial_struct_time)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16137
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2012-10-04 Thread R. David Murray

R. David Murray added the comment:

I can't reproduce this.  What version of 2.7?  (This might have been fixed by 
the issue 8013 fix).

--
nosy: +r.david.murray

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16137
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16137] Using time.asctime() with an array with negative tm_hour causes Python Crash.

2012-10-04 Thread Kushal Das

Kushal Das added the comment:

Can not reproduce this on 2.7.3 on Fedora 17, x86_64.

--
nosy: +kushaldas

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16137
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com