diff options
| author | tgoodwin <tgoodwin> | 1998-07-20 10:12:46 +0000 |
|---|---|---|
| committer | Toby Goodwin <toby@paccrat.org> | 2015-05-16 21:23:09 +0100 |
| commit | 096de180211a0573a80d9380aae99b940ce46a42 (patch) | |
| tree | 7c0bb40d28f65e6be3ff0aa092f91fe293ae8200 | |
| parent | 7203d4edba0affd77b257610a2fa6e23a37a8da6 (diff) | |
only call WTERMSIG if WIFSIGNALED
also, always check that WTERMSIG is in range
| -rw-r--r-- | status.c | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -64,7 +64,8 @@ extern void setstatus(pid_t pid, int i) { extern void statprint(pid_t pid, int i) { if (WIFSIGNALED(i)) { - char *msg = (WTERMSIG(i) < NUMOFSIGNALS ? signals[WTERMSIG(i)].msg : ""); + int t = WTERMSIG(i); + char *msg = ((t > 0) && (t < NUMOFSIGNALS) ? signals[WTERMSIG(i)].msg : ""); if (pid != -1) fprint(2, "%ld: ", (long)pid); if (myWIFDUMPED(i)) { @@ -99,11 +100,10 @@ extern List *sgetstatus() { /* return status as a string (used above and for bqstatus) */ extern char *strstatus(int s) { - int t = WTERMSIG(s); - - if (t != 0) { + if (WIFSIGNALED(s)) { + int t = WTERMSIG(s); const char *core = myWIFDUMPED(s) ? "+core" : ""; - if (t < NUMOFSIGNALS && *signals[t].name != '\0') + if ((t > 0) && (t < NUMOFSIGNALS) && *signals[t].name != '\0') return nprint("%s%s", signals[t].name, core); else return nprint("-%d%s", t, core); /* unknown signals are negated */ |