Mail Archives: djgpp/2001/09/23/11:51:45
> 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 -