[OpenAFS-devel] butc crash on linux/amd64

Sidney Cammeresi sac@cheesecake.org
Wed, 1 Mar 2006 12:35:22 -0600


--3V7upXqbjpZ4EhLz
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

I'm an AFS newbie, setting up a new cell on an AMD64 machine running
Debian 3.1 and the OpenAFS 1.4.0 packages from unstable.

I was experimenting with backups when I hit a crash in butc after hitting
enter at the `insert a tape' prompt.

Program received signal SIGSEGV, Segmentation fault.
ktimeDate_FromInt32 (timeSecs=1141237580, ktimePtr=0x594a60)
    at ./kreltime.c:122
122         ktimePtr->sec = timePtr->tm_sec;
(gdb) bt
#0  ktimeDate_FromInt32 (timeSecs=1141237580, ktimePtr=0x594a60)
    at ./kreltime.c:122
#1  0x000000000045fcc4 in Add_RelDate_to_Time (relDatePtr=0x2a95ef3788,
    atime=-383805929) at ./kreltime.c:290
#2  0x0000000000412004 in calcExpirationDate (expType=-1673440488,
expDate=-1,
    createTime=1141237580) at dump.c:162
#3  0x0000000000412729 in getDumpTape (dparamsPtr=0x2a95ef5288,
    interactiveFlag=1873051225, append=0) at dump.c:1753
#4  0x0000000000414bb1 in Dumper (nodePtr=0x5caed0) at dump.c:1229
#5  0x000000000045af58 in Create_Process_Part2 () at ./lwp.c:778
#6  0x0000002a957ca1a0 in swapcontext () from /lib/libc.so.6

Turns out timePtr was null.  On a guess, I changed the localtime call
to localtime_r (and made the other changes that required), and butc
stopped crashing.

I don't know enough about all the various systems OpenAFS supports to
say whether this is correct across the board, but it fixes the crash
on my machine, at least, so here it is, FWIW.

Patch attached, which should work in 1.4.1 as well, as I see kreltime.c
is the same in both versions (didn't check 1.5.0).

-- 
Sidney CAMMERESI
http://www.cheesecake.org/sac/

--3V7upXqbjpZ4EhLz
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="kreltime.c.diff"

--- kreltime.c.dist	2006-03-01 12:08:32.069118581 -0600
+++ kreltime.c	2006-03-01 12:04:31.279760350 -0600
@@ -114,17 +114,17 @@
 int
 ktimeDate_FromInt32(afs_int32 timeSecs, struct ktime_date *ktimePtr)
 {
-    struct tm *timePtr;
+    struct tm tm;
 
-    timePtr = localtime((time_t *) & timeSecs);
+    localtime_r((time_t *) & timeSecs, &tm);
 
     /* copy the relevant fields */
-    ktimePtr->sec = timePtr->tm_sec;
-    ktimePtr->min = timePtr->tm_min;
-    ktimePtr->hour = timePtr->tm_hour;
-    ktimePtr->day = timePtr->tm_mday;
-    ktimePtr->month = timePtr->tm_mon + 1;
-    ktimePtr->year = timePtr->tm_year;
+    ktimePtr->sec = tm.tm_sec;
+    ktimePtr->min = tm.tm_min;
+    ktimePtr->hour = tm.tm_hour;
+    ktimePtr->day = tm.tm_mday;
+    ktimePtr->month = tm.tm_mon + 1;
+    ktimePtr->year = tm.tm_year;
 
     ktimePtr->mask =
 	KTIMEDATE_YEAR | KTIMEDATE_MONTH | KTIMEDATE_DAY | KTIMEDATE_HOUR |

--3V7upXqbjpZ4EhLz--