This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author belopolsky
Recipients AmirHabibi, abbeyj, alexandre.vassalotti, belopolsky, brett.cannon, lemburg, pitrou, srid
Date 2010-06-03.15:06:01
SpamBayes Score 3.308221e-05
Marked as misclassified No
Message-id <1275577564.28.0.333979037855.issue6608@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2010-06-03 15:06:04belopolskysetrecipients: + belopolsky, lemburg, brett.cannon, pitrou, alexandre.vassalotti, srid, abbeyj, AmirHabibi
2010-06-03 15:06:04belopolskysetmessageid: <1275577564.28.0.333979037855.issue6608@psf.upfronthosting.co.za>
2010-06-03 15:06:03belopolskylinkissue6608 messages
2010-06-03 15:06:01belopolskycreate