delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/09/23/11:51:45

Date: Sun, 23 Sep 2001 18:50:01 +0300
From: "Eli Zaretskii" <eliz AT is DOT elta DOT co DOT il>
Sender: halo1 AT zahav DOT net DOT il
To: "A. Sinan Unur" <asu1 AT cornell DOT edu>
Message-Id: <2593-Sun23Sep2001185000+0300-eliz@is.elta.co.il>
X-Mailer: Emacs 20.6 (via feedmail 8.3.emacs20_6 I) and Blat ver 1.8.9
CC: djgpp AT delorie DOT com
In-reply-to: <Xns912564D96128FASINANUNUR@132.236.56.8> (asu1@cornell.edu)
Subject: Re: which crashes
References: <Xns912564D96128FASINANUNUR AT 132 DOT 236 DOT 56 DOT 8>
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> From: "A. Sinan Unur" <asu1 AT cornell DOT edu>
> Newsgroups: comp.os.msdos.djgpp
> Date: 23 Sep 2001 13:54:49 GMT
> 
> C:\VAR>which xcopy
> Exiting due to signal SIGSEGV
> Page fault at eip=00003515, error=0004
> eax=00000000 ebx=0009a1fc ecx=00000000 edx=00000000 esi=0009b17a 
> edi=00000014
> ebp=00098f70 esp=00098f40 program=C:\DJGPP\BIN\WHICH.EXE

It's a bug in which: the DJGPP-specific code has a cut-n-paste snafu
in the second for loop in function find_command_in_path.  See the
patch below.

FWIW, I think there's one more, this time harmless, bug in both for
loops: the call to strlen(full_path) inside the call to xrealloc
causes the allocated string to grow larger and larger, for no good
reason.  If someone plans on uploading a fixed version (hint, hint ;-),
I'd suggest to fix that as well...

> === AUTOEXEC.BAT (relevant section) ===

You didn't show all the relevant sections, I think: the bug only
raises its ugly head if the environment variable WHICH is set.  This
is the risk in showing ``only relevant sections'' ;-)

Finally, I'd think the code needs to guard itself better against
invalid strings in the WHICH variable.  With such a general name, who
knows what the value might be?..


diff -up "which.c~" "which.c"
--- which.c~	Sun Aug 27 10:08:52 2000
+++ which.c	Sun Sep 23 18:40:26 2001
@@ -216,7 +216,7 @@ static char *find_command_in_path(const 
          ext = strtok((char *) 0, " ,;")) {
       // Realloc space for the path + extension
       // (Do this every time to account for varying length extensions)
-      full_path = (char *) xrealloc(full_path, 1 + strlen(exts[indx]) + strlen(full_path));
+      full_path = (char *) xrealloc(full_path, 1 + strlen(ext) + strlen(full_path));
       // Create a pointer to the end of the path
       full_path_end = full_path + full_path_len;
       // Copy the extension onto the end of the path

Diff finished at Sun Sep 23 18:48:02

- Raw text -


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