<<On Fri, 10 Jan 1997 15:38:45 -0800, Paul Eggert <eggert@twinsun.com> said:
That is the best way, and in fact the tz code is supposed to do that already. I just took a quick look and I couldn't see any holes in its checking, though I didn't look that carefully.
It turns out that it is doing the proper checking, but it is not doing a good job of cleaning up the mess. Here are more segments of my debugging typescript: gmtload (sp=0x24124) at /usr/wd1/src/lib/libc/stdtime/localtime.c:921 921 (void) tzparse(gmt, sp, TRUE); (gdb) s tzparse (name=0x128d0 "GMT", sp=0x24124, lastditch=1) at /usr/wd1/src/lib/libc/stdtime/localtime.c:720 720 INITIALIZE(dstname); (gdb) 721 stdname = name; (gdb) 722 if (lastditch) { (gdb) 723 stdlen = strlen(name); /* length of standard zone name */ (gdb) 724 name += stdlen; (gdb) 725 if (stdlen >= sizeof sp->chars) (gdb) 727 } else { (gdb) 733 if (*name == '\0') (gdb) 734 return -1; /* was "stdoffset = 0;" */ (gdb) p *sp $13 = {leapcnt = 1919905652, timecnt = 544173600, typecnt = 1802002806, charcnt = 1919512165, ats = {0 <repeats 370 times>}, types = '\000' <repeats 369 times>, ttis = {{tt_gmtoff = 0, tt_isdst = 0, tt_abbrind = 0, tt_ttisstd = 0, tt_ttisgmt = 0} <repeats 256 times>}, chars = '\000' <repeats 511 times>, lsis = {{ls_trans = 0, ls_corr = 0} <repeats 50 times>}} (gdb) n 914 } (gdb) gmtload (sp=0x24124) at /usr/wd1/src/lib/libc/stdtime/localtime.c:922 922 } (gdb) tzset () at /usr/wd1/src/lib/libc/stdtime/localtime.c:1010 1010 settzname(); (gdb) (and of course, settzname() is where it already blows up...) Line 734 above appears to be the error; it doesn't take into account the possibility that this is a `lasatditch' attempt. The following patch appears to fix the problem: --- localtime.c.ORIG Mon Jan 13 12:00:35 1997 +++ localtime.c Mon Jan 13 12:01:20 1997 @@ -724,18 +724,19 @@ name += stdlen; if (stdlen >= sizeof sp->chars) stdlen = (sizeof sp->chars) - 1; + stdoffset = 0; } else { name = getzname(name); stdlen = name - stdname; if (stdlen < 3) return -1; - } - if (*name == '\0') - return -1; /* was "stdoffset = 0;" */ - else { - name = getoffset(name, &stdoffset); - if (name == NULL) - return -1; + if (*name == '\0') + return -1; /* was "stdoffset = 0;" */ + else { + name = getoffset(name, &stdoffset); + if (name == NULL) + return -1; + } } load_result = tzload(TZDEFRULES, sp); if (load_result != 0) -GAWollman -- Garrett A. Wollman | O Siem / We are all family / O Siem / We're all the same wollman@lcs.mit.edu | O Siem / The fires of freedom Opinions not those of| Dance in the burning flame MIT, LCS, ANA, or NSA| - Susan Aglukark and Chad Irschick