bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

crash under cygwin if a program exits with an exotic signal


From: Varga Zoltan
Subject: crash under cygwin if a program exits with an exotic signal
Date: Wed, 2 Jul 2003 23:17:43 +0200 (CEST)

Configuration Information [Automatically generated, do not
change]:             Machine: i686
OS: cygwin
Compiler: i686-pc-cygwin-gcc
Compilation CFLAGS:  -DPROGRAM='bash.exe'
-DCONF_HOSTTYPE='i686' -DCONF_OSTYPE=\
'cygwin' -DCONF_MACHTYPE='i686-pc-cygwin' -DCONF_VENDOR='pc'
-DSHELL -DHAVE_CON\
FIG_H -DRECYCLES_PIDS  -I.  -I../bash-2.05b
-I../bash-2.05b/include -I../bash-2\
.05b/lib  -g -O2
uname output: CYGWIN_NT-5.0 D6300330 1.3.22(0.78/3/2)
2003-03-18 09:20 i686 unk\
nown unknown Cygwin
Machine Type: i686-pc-cygwin

Bash Version: 2.05b

Description:
When I run a program written using Microsofts .NET
framework, and
the program exits because of an ucaught exception, the bash
shell
I was running the program from crashes.

Repeat-By:
- Write and compile a simple C# program such as this:
<<<<<<<<<<<<<<
using System;
class Bug {
public static void Main () {
    throw new Exception ();
}
}
<<<<<<<<<<<<<<<
- Run it from a bash prompt
-  in the resulting window, click OK
- watch bash crash

Fix:
I debugged this, and the problem seems to be in line 2842 in
jobs.c.
When the .NET program exits, WTERMSIG returns 79 as the signal
number for the program, this number is then fed to
strsignal() which
returns 0. gcc optimizes the call fprintf (stderr, "%s",
...) into
fputs (..., stderr), so fputs gets passed a NULL pointer as
its first 
argument leading to a crash.

The fix is to explicitly check the return value of strsignal:

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
diff -u bash-orig/jobs.c bash-2.05b/jobs.c
--- bash-orig/jobs.c    2003-07-02 23:14:59.000000000 +0200
+++ bash-2.05b/jobs.c   2003-07-02 23:12:01.000000000 +0200
@@ -1037,6 +1037,9 @@
        temp = "Unknown status";
     }
 
+  if (temp == NULL)
+       temp = "Unknown status";
+
   return temp;
 }
 
@@ -2768,6 +2771,7 @@
 {
   register int job, termsig;
   char *dir;
+  const char *strsig;
   sigset_t set, oset;
   WAIT s;
 
@@ -2839,7 +2843,9 @@
                  if (termsig && WIFSIGNALED (s) && termsig != SIGINT &&
termsig != SIGPIPE)
 #endif
                    {
-                     fprintf (stderr, "%s", strsignal (termsig));
+                         strsig = strsignal (termsig);
+                         if (strsig)
+                               fprintf (stderr, "%s", strsig);
 
                      if (WIFCORED (s))
                        fprintf (stderr, " (core dumped)");
diff -u bash-orig/nojobs.c bash-2.05b/nojobs.c
--- bash-orig/nojobs.c  2003-07-02 23:15:13.000000000 +0200
+++ bash-2.05b/nojobs.c 2003-07-02 23:12:35.000000000 +0200
@@ -696,6 +696,7 @@
 {
   int return_val, pstatus;
   pid_t got_pid;
+  const char *strsig;
   WAIT status;
 
   pstatus = find_status_by_pid (pid);
@@ -771,7 +772,9 @@
        (WTERMSIG (status) != SIGINT) && (WTERMSIG (status) !=
SIGPIPE))
 #endif
     {
-      fprintf (stderr, "%s", strsignal (WTERMSIG (status)));
+         strsig = strsignal (WTERMSIG (status));
+         if (strsig)
+               fprintf (stderr, "%s", strsig);
       if (WIFCORED (status))
        fprintf (stderr, " (core dumped)");
       fprintf (stderr, "\n");

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
















reply via email to

[Prev in Thread] Current Thread [Next in Thread]