Friday, February 17, 2006

Fix: Time::Piece::strftime() causes coredump on OpenBSD 3.8-i368

I might have been able to find a fix. It is applicable to Time::Piece v1.09. I have already sent a patch to Time::Piece maintainer. For convenience, I'll provide it here too:


Matt,

I might have been able to identify the culprit. It looks like the following statement in Piece.xs(line 26):

#ifdef HAS_GNULIBC

meant to read:

#if !defined(HAS_GNULIBC)

as BSD systems are obviously not GNULIBC based. Once I applied this change, coredumps went away (on OpenBSD). Also, I added an zero-ization of 'mytm' at line 819:

memset(&mytm, 0, sizeof(mytm));

Now it seems working perfectly fine on OpenBSD and Linux (Debian Sarge stable). Please find a patch attached in case you'd like to include it in next release of the package. Thank you.


Here is the patch itself:


--- /home/olga/tmp/Time-Piece-1.09/Piece.xs 2005-11-15 17:46:23.000000000 -0500
+++ Piece.xs 2006-02-17 22:23:28.000000000 -0500
@@ -23,7 +23,7 @@
* support is added and NETaa14816 is considered in full.
* It does not address tzname aspects of NETaa14816.
*/
-#ifdef HAS_GNULIBC
+#if !defined(HAS_GNULIBC)
# ifndef STRUCT_TM_HASZONE
# define STRUCT_TM_HASZONE
# else
@@ -816,6 +816,7 @@
char tmpbuf[128];
struct tm mytm;
int len;
+ memset(&mytm, 0, sizeof(mytm));
my_init_tm(&mytm); /* XXX workaround - see my_init_tm() above */
mytm.tm_sec = sec;
mytm.tm_min = min;


To apply obtain and extract the Time::Piece v1.09 (http://search.cpan.org/CPAN/authors/id/M/MS/MSERGEANT/Time-Piece-1.09.tar.gz). Then go to Time-Piece-1.09 directory, copy patch file there and apply it:


patch <patch

Continue on to build the package as usual. Enjoy!

No comments: