http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47802
--- Comment #6 from Jeffrey A. Law <law at redhat dot com> 2011-02-21 16:56:18 UTC --- -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 02/18/11 13:56, dave at hiauly1 dot hia.nrc.ca wrote: > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47802 > > --- Comment #2 from dave at hiauly1 dot hia.nrc.ca 2011-02-18 20:56:54 UTC --- >> Is there no way to get a posix compliant ctime? Alternatively, we'll need >> autoconf magic to detect the extra arg. I know at one time it was relatively >> common, so autoconf magic might be around somewhere. Assuming it is you just >> have to do something like >> >> >> #if defined (oddballctime) >> *date = ctime_r (&now, cbuf, CSZ); >> #else >> *date = ctime_r (&now, cbuf); >> #endif > > Using ctime_r is a bit of a can of worms. The GNU autoconf manual recommends > not using ctime_r unless the inputs are known to be within certain limits. Correct. The problem is some implementations can trigger buffer overflows for bad input. Certain implementations pass in a buffer size parameter to deal with that problem, others (glibc) presumably do some checking before dumping results into the user supplied buffer to make sure they don't exceed the 26 bytes or whatever the minimum size of hte buffer is supposed to be. Even for checking versions like glibc, if the wrong sized buffer is passed in, then it'll probably break. I guess the question we need to ask is how important are these routines and should we be issuing warnings when they are used, much like is done with gets. If we don't need them, I'd much prefer to see them go away as they're a rats nest of security issues. Just a quick glance at the code in libgfortran/ctime.c and I'm pretty sure it's vulnerable to a buffer overflow attack. Jeff -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJNYpkoAAoJEBRtltQi2kC7HwcH/3IEgG2sh265kwu9kKQQ87gf um1qKykJo4/Ph3W4UF7q1G26mw5luemVE6ga4+4nEzpivH0hzgsxWADDPXjQzq26 tqUXwh0nKi5665O1rcW88EZpej5J0MDLtUBTQXv1DipQWDBa/YjDqrmO4IRkw+MK QlkgPvCqosS1wvlbVJ9xKpTn2XY8tVTPdLlAMI3iBbbtDcsWMdKxaG5mpnhh8P4i HkVepfpRr5RtpuVN3SJ6AWhqR0PQgS1e2PB2WbbY8bvNy5ev1GggJZj/3j101jza /QseJ16lj3CqOMHCppHOhXGL8bxMFW17AWv/hL74+gTn9rZCH/JUjOQ+YzRgs0A= =SpA9 -----END PGP SIGNATURE-----