Alexander Belopolsky <belopol...@users.sourceforge.net> added the comment:

Here is a quote from the relevant CERT advisory (MSC33-C):

"""
This function is supposed to output a character string of 26 positions at most, 
including the terminating zero. If we count the length indicated by the format 
directives we arrive at 25. Taking into account the terminating zero, the array 
size of the string appears sufficient.

However, this implementation assumes that the values of the struct tm data in 
timeptr are within normal ranges, and does nothing to enforce this. If any of 
the values print more characters than expected, the sprintf() function may 
overflow the result array. For instance, if tm_year has the value 12345, then 
27 characters (including the terminating null character) are printed, resulting 
in a buffer overflow.

The asctime() function primarily exists for compatibility with older 
implementations. Also, the asctime() function does not support localized date 
and time formats. The POSIX standard developers decided to mark the asctime() 
function obsolescent even though they are in C99 because of the possibility of 
buffer overflow.

C99 also provides the strftime() function which can be used to avoid these 
problems.
""" 
https://www.securecoding.cert.org/confluence/display/seccode/MSC33-C.+Do+not+pass+invalid+data+to+the+asctime%28%29+function

(I am changing the stage back to "needs patch" because the current patch  is 
vulnerable to buffer overflow.)

I think it is best to leave the code as is and possibly add a warning in 
documentation that passing hand-crafted timetuple is unsafe on some systems and 
that locale aware strftime("%c", ..) is preferable to asctime.

----------
stage: patch review -> needs patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue6608>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to