www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/28/23:33:58

From: bukinm AT inp DOT nsk DOT su (Michael Bukin)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Emacs 22 env vars bug
Date: Thu, 24 Jul 1997 06:41:43 GMT
Organization: BINP SD RAS
Lines: 97
Message-ID: <33d7e79d.10682519@news-win.inp.nsk.su>
References: <Pine DOT SOL DOT 3 DOT 96 DOT 970715124917 DOT 6183A-100000 AT kruuna DOT Helsinki DOT FI>
Reply-To: bukinm AT inp DOT nsk DOT su
NNTP-Posting-Host: csd-bsdi.inp.nsk.su
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Tue, 15 Jul 1997 10:00:17 GMT, Esa A E Peuha <peuha AT cc DOT helsinki DOT fi>
wrote:

> On Sun, 13 Jul 1997, Eli Zaretskii wrote:
> 
> > Yes, I also get the crash traceback which points into `gmalloc' (which
> > is GNU's replacement for `malloc' and friends).  But I'm clueless as
> > to why does it crash there, or why only for .exe built on my machine?
> 

I have tried rebuilding emacs, but my results are different:

***** crash.txt *****
D:\TEMP\GNU\EMACS\BIN>emacs.exe
Exiting due to signal SIGSEGV
General Protection Fault at eip=0007481f
eax=1011dc2c ebx=00070d02 ecx=0000006c edx=00000145 esi=00115364
edi=00070d02
ebp=00220f44 esp=00220f38 program=D:\TEMP\GNU\EMACS\BIN\EMACS.EXE
cs: sel=00a7  base=82f89000  limit=0025ffff
ds: sel=00af  base=82f89000  limit=0025ffff
es: sel=00af  base=82f89000  limit=0025ffff
fs: sel=0087  base=00017480  limit=0000ffff
gs: sel=00cf  base=00000000  limit=ffffffff
ss: sel=00af  base=82f89000  limit=0025ffff

Call frame traceback EIPs:
  0x0007481f   _getenv+47, line 20 of getenv.c
  0x00070d68   _internal_terminal_init+72, line 916 of msdos.c
  0x00025972   _init_sys_modes+70, line 1424 of sysdep.c
  0x00018387   _main+1151, line 832 of emacs.c
  0x0007a51a   ___crt1_startup+138
***** end of crash.txt *****

In getenv eax holds environ[i] and it is out of selector limit.

(Emacs was compiled as suggested in `INSTALL':
unzip em1934*.zip; cd gnu/emacs; config msdos; make install.
Only added getenv.c for line numbers in traceback).


-----
There is a bug in putenv (when allocating bigger chunk for
environ, one element is not counted).
This bug can explain magic number 21.

Here is a patch:

***** putenv.fix ****
*** putenv.c	Sun Oct  6 00:27:44 1996
--- d:/temp/gnu/emacs/src/putenv.c	Thu Jul 24 10:26:06 1997
***************
*** 53,59 ****
    if (putenv_bss_count != __bss_count
        || environ       != prev_environ)
    {
!     putenv_bss_count = __bss_count;
      for (ecount=0; environ[ecount]; ecount++);
      emax = ecount;
      /* Bump the count to a value no function has yet seen,
--- 53,59 ----
    if (putenv_bss_count != __bss_count
        || environ       != prev_environ)
    {
!     /* putenv_bss_count = __bss_count; */
      for (ecount=0; environ[ecount]; ecount++);
      emax = ecount;
      /* Bump the count to a value no function has yet seen,
***************
*** 105,112 ****
    if (ecount >= emax)
    {
      char **enew;
      emax += 10;
!     enew = (char **)malloc(emax * sizeof(char *));
      if (enew == 0)
        return -1;
      memcpy(enew, environ, ecount * sizeof(char *));
--- 105,113 ----
    if (ecount >= emax)
    {
      char **enew;
+     /* (environ[emax] == 0) when environ is full.  */
      emax += 10;
!     enew = (char **)malloc((emax + 1) * sizeof(char *));
      if (enew == 0)
        return -1;
      memcpy(enew, environ, ecount * sizeof(char *));
***** end of putenv.fix *****

The line with `putenv_bss_count = __bss_count;' was commented,
because later there is a test for `putenv_bss_count != __bss_count'.
(This can be left as it was, but it should be changed somehow).

Emacs compiled with patched putenv does not crash,
but emacs compiled without it does.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019