SunOS 4.1 localtime bug

Eirik Fuller eirik at elf.tn.cornell.edu
Fri May 25 03:53:40 AEST 1990


The release notes for SunOS 4.1 suggest #define SYSTEM_MALLOC for GNU
emacs, to avoid an abort in GNU malloc.  The enclosed patch gives a
workaround for GNU malloc so that it too can dodge a bug in localtime and
avoid this abort.  The enclosed script demonstrates the localtime bug
without using any GNU software.

*** malloc.c~	Fri Apr  7 22:12:10 1989
--- malloc.c	Tue May  8 07:07:22 1990
***************
*** 476,482 ****
--- 476,487 ----
       multiple of 8, then figure out which nestf[] area to use.
       Both the beginning of the header and the beginning of the
       block should be on an eight byte boundary.  */
+ #ifdef SUNOS_LOCALTIME_BUG
+   /* SunOS 4.1 localtime scribbles on the ninth byte.  */
+   nbytes = (n + ((sizeof *p + 15) & ~15) + EXTRA + 15) & ~15;
+ #else
    nbytes = (n + ((sizeof *p + 7) & ~7) + EXTRA + 7) & ~7;
+ #endif
    {
      register unsigned int   shiftr = (nbytes - 1) >> 2;


#!/bin/sh -
# This script demonstrates a bug in SunOS 4.1 localtime.o
# It shows a call to calloc that allocates eight bytes, and the value
# returned by calloc.  Then it stops just before the instruction that
# writes the next byte past the eight byte region allocated by that
# call to calloc. The breakpoint at free is to show that the region is
# not freed in the meantime.

cat << 'EOF' > t.c
main ()
{
  tzsetwall();
  exit (0);
}
EOF
echo cc -Bstatic -o t t.c
cc -Bstatic -o t t.c
echo adb t
adb t << 'EOF'
tzsetwall-126c:b
:r
:s
:s
:s
!echo '#' 'calloc(8,1)'
<i0=X
<i1=X
tzsetwall-1264:b
:c
!echo '#' return value of 'calloc(8,1)'
<o0=X
free:b
tzsetwall-0db8:b
!echo '#' zero ninth byte
:c
<l4=X
<i0=X
<l4/s

EOF



More information about the Comp.sys.sun mailing list