Handle proper formatting and a buffer overrun when running an old sh on
a system that has sys_nsig > NSIG (i.e. when libc is upgraded.) Submitted by: Matt Dillon Reviewed by: bde
This commit is contained in:
parent
06d2a666e4
commit
97054a769f
@ -89,6 +89,8 @@ static int getsigaction(int, sig_t *);
|
||||
|
||||
/*
|
||||
* Map a string to a signal number.
|
||||
*
|
||||
* Note: the signal number may exceed NSIG.
|
||||
*/
|
||||
static int
|
||||
sigstring_to_signum(char *sig)
|
||||
@ -120,14 +122,24 @@ sigstring_to_signum(char *sig)
|
||||
static void
|
||||
printsignals(void)
|
||||
{
|
||||
int n;
|
||||
int n, outlen;
|
||||
|
||||
outlen = 0;
|
||||
for (n = 1; n < sys_nsig; n++) {
|
||||
out1fmt("%s", sys_signame[n]);
|
||||
if (n == (NSIG / 2) || n == (NSIG - 1))
|
||||
if (sys_signame[n]) {
|
||||
out1fmt("%s", sys_signame[n]);
|
||||
outlen += strlen(sys_signame[n]);
|
||||
} else {
|
||||
out1fmt("%d", n);
|
||||
outlen += 3; /* good enough */
|
||||
}
|
||||
++outlen;
|
||||
if (outlen > 70 || n == sys_nsig - 1) {
|
||||
out1str("\n");
|
||||
else
|
||||
outlen = 0;
|
||||
} else {
|
||||
out1c(' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,9 +155,18 @@ trapcmd(int argc, char **argv)
|
||||
|
||||
if (argc <= 1) {
|
||||
for (signo = 0 ; signo < sys_nsig ; signo++) {
|
||||
if (trap[signo] != NULL)
|
||||
out1fmt("trap -- '%s' %s\n", trap[signo],
|
||||
(signo) ? sys_signame[signo] : "exit");
|
||||
if (signo < NSIG && trap[signo] != NULL) {
|
||||
if (signo == 0) {
|
||||
out1fmt("trap -- '%s' %s\n",
|
||||
trap[signo], "exit");
|
||||
} else if (sys_signame[signo]) {
|
||||
out1fmt("trap -- '%s' %s\n",
|
||||
trap[signo], sys_signame[signo]);
|
||||
} else {
|
||||
out1fmt("trap -- '%s' %d\n",
|
||||
trap[signo], signo);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user