[15544] in Athena Bugs
tcsh kill -l dumps core on SGI
daemon@ATHENA.MIT.EDU (Larry Stone)
Mon Sep 29 19:13:12 1997
Date: Mon, 29 Sep 97 19:13:09 EDT
From: Larry Stone <lcs@MIT.EDU>
To: bugs@MIT.EDU
Here's the bug and a fix:
Entering kill -l (or anything that lists signals, e.g. kill -FOO, or invoking
completion on a signal name) causes tcsh to dump core on the SGI. Running
Athena 8.1.
The fix is to make it check the length of the signal name table, since it
may be less than NSIG. I chose to fix it this way rather than simply
extend the table to NSIG because (a) there is always a good chance that the
assumptions in sh.init.c will be wrong in the future and for some OS, the
maze of nested #ifdef's won't include enough entries for NSIG, so just fixing
this case means the same thing is likely to happen again. And, (b) extending
the array at runtime is clumsy in C and not useful, as it would just be
filled with null entries.
Also, why are we running tcsh source that's 5 years old? I'm new here, so
pardon the naive question.
Here are the diffs to fix it:
Index: sh.h
===================================================================
RCS file: /afs/dev.mit.edu/source/repository/third/tcsh/sh.h,v
retrieving revision 1.2
diff -c -b -w -r1.2 sh.h
*** sh.h 1996/10/08 14:18:19 1.2
--- sh.h 1997/09/29 21:42:42
***************
*** 965,970 ****
--- 965,971 ----
char *iname; /* name from /usr/include */
char *pname; /* print name */
} mesg[];
+ extern int mesg_size; /* number of entries in mesg, may be fewer than NSIG */
/* word_chars is set by default to WORD_CHARS but can be overridden by
the worchars variable--if unset, reverts to WORD_CHARS */
Index: sh.init.c
===================================================================
RCS file: /afs/dev.mit.edu/source/repository/third/tcsh/sh.init.c,v
retrieving revision 1.1.1.1
diff -c -b -w -r1.1.1.1 sh.init.c
*** sh.init.c 1996/10/02 06:09:21 1.1.1.1
--- sh.init.c 1997/09/29 21:41:53
***************
*** 497,502 ****
--- 497,536 ----
# else /* !SOLARIS2 */
/* 32 */ 0, "Maximum number of signals",
# endif /* SOLARIS2 */
+
+ # else /* SYSVREL > 3 */ /* IRIX 5.3 is SVR4 compliant .. */
+ # ifdef IRIS4D
+ # define _sigextra_
+ /* 20 */ "STOP", MSG_STOP,
+ /* 21 */ "TSTP", MSG_TSTP,
+ /* 22 */ "POLL", "Stream I/O pending",
+ /* 23 */ "IO", "Asynchronous I/O (select)",
+ /* 24 */ "URG", "Urgent condition on IO channel",
+ /* 25 */ "WINCH", "Window changed",
+ /* 26 */ "VTALRM", "Virtual time alarm",
+ /* 27 */ "PROF", "Profiling time alarm",
+ /* 28 */ "CONT", "Continued",
+ /* 29 */ "TTIN", MSG_TTIN,
+ /* 30 */ "TTOU", MSG_TTOU,
+ /* 31 */ 0, "Signal 31",
+ /* 32 */ 0, "Signal 32",
+ # endif /* IRIS4D */
+ # ifdef IRIS3D
+ # define _sigextra_
+ /* 20 */ 0, "Signal 20",
+ /* 21 */ 0, "Signal 21",
+ /* 22 */ 0, "Signal 22",
+ /* 23 */ 0, "Signal 23",
+ /* 24 */ 0, "Signal 24",
+ /* 25 */ "WINCH", "Window changed",
+ /* 26 */ "IO", "Asynchronous I/O (select)",
+ /* 27 */ "URG", "Urgent condition on IO channel",
+ /* 28 */ "POLL", "Stream I/O pending",
+ /* 29 */ 0, "Signal 29",
+ /* 30 */ 0, "Signal 30",
+ /* 31 */ 0, "Signal 31",
+ /* 32 */ 0, "Signal 32",
+ # endif /* IRIS3D */
# endif /* SYSVREL > 3 */
# if defined(ISC) && defined(POSIX)
***************
*** 533,571 ****
/* 32 */ 0, "Maximum number of signals",
# endif /* SCO && POSIX */
- # ifdef IRIS4D
- # define _sigextra_
- /* 20 */ "STOP", MSG_STOP,
- /* 21 */ "TSTP", MSG_TSTP,
- /* 22 */ "POLL", "Stream I/O pending",
- /* 23 */ "IO", "Asynchronous I/O (select)",
- /* 24 */ "URG", "Urgent condition on IO channel",
- /* 25 */ "WINCH", "Window changed",
- /* 26 */ "VTALRM", "Virtual time alarm",
- /* 27 */ "PROF", "Profiling time alarm",
- /* 28 */ "CONT", "Continued",
- /* 29 */ "TTIN", MSG_TTIN,
- /* 30 */ "TTOU", MSG_TTOU,
- /* 31 */ 0, "Signal 31",
- /* 32 */ 0, "Signal 32",
- # endif /* IRIS4D */
-
- # ifdef IRIS3D
- # define _sigextra_
- /* 20 */ 0, "Signal 20",
- /* 21 */ 0, "Signal 21",
- /* 22 */ 0, "Signal 22",
- /* 23 */ 0, "Signal 23",
- /* 24 */ 0, "Signal 24",
- /* 25 */ "WINCH", "Window changed",
- /* 26 */ "IO", "Asynchronous I/O (select)",
- /* 27 */ "URG", "Urgent condition on IO channel",
- /* 28 */ "POLL", "Stream I/O pending",
- /* 29 */ 0, "Signal 29",
- /* 30 */ 0, "Signal 30",
- /* 31 */ 0, "Signal 31",
- /* 32 */ 0, "Signal 32",
- # endif /* IRIS3D */
# ifdef apollo
# define _sigextra_
--- 567,572 ----
***************
*** 864,866 ****
--- 865,869 ----
/* 65 */ 0, "Signal 65"
#endif /* POSIX */
};
+
+ int mesg_size = sizeof(mesg) / sizeof(struct mesg);
Index: sh.proc.c
===================================================================
RCS file: /afs/dev.mit.edu/source/repository/third/tcsh/sh.proc.c,v
retrieving revision 1.1.1.1
diff -c -b -w -r1.1.1.1 sh.proc.c
*** sh.proc.c 1996/10/02 06:09:22 1.1.1.1
--- sh.proc.c 1997/09/29 21:43:45
***************
*** 1458,1464 ****
v++;
if (v[0] && v[0][0] == '-') {
if (v[0][1] == 'l') {
! for (signum = 1; signum <= NSIG; signum++) {
if ((name = mesg[signum].iname) != NULL) {
len += strlen(name) + 1;
if (len >= T_Cols - 1) {
--- 1458,1464 ----
v++;
if (v[0] && v[0][0] == '-') {
if (v[0][1] == 'l') {
! for (signum = 1; signum <= NSIG && signum < mesg_size; signum++) {
if ((name = mesg[signum].iname) != NULL) {
len += strlen(name) + 1;
if (len >= T_Cols - 1) {
***************
*** 1477,1483 ****
stderror(ERR_NAME | ERR_BADSIG);
}
else {
! for (signum = 1; signum <= NSIG; signum++)
if (mesg[signum].iname &&
eq(&v[0][1], str2short(mesg[signum].iname)))
goto gotsig;
--- 1477,1483 ----
stderror(ERR_NAME | ERR_BADSIG);
}
else {
! for (signum = 1; signum <= NSIG && signum < mesg_size; signum++)
if (mesg[signum].iname &&
eq(&v[0][1], str2short(mesg[signum].iname)))
goto gotsig;
Index: tw.init.c
===================================================================
RCS file: /afs/dev.mit.edu/source/repository/third/tcsh/tw.init.c,v
retrieving revision 1.1.1.1
diff -c -b -w -r1.1.1.1 tw.init.c
*** tw.init.c 1996/10/02 06:09:24 1.1.1.1
--- tw.init.c 1997/09/29 21:45:19
***************
*** 928,934 ****
int *flags;
{
char *ptr;
! for (;tw_index < NSIG; tw_index++) {
if (mesg[tw_index].iname == NULL)
continue;
--- 928,935 ----
int *flags;
{
char *ptr;
!
! for (;tw_index < NSIG && tw_index < mesg_size; tw_index++) {
if (mesg[tw_index].iname == NULL)
continue;